Arm Linux Kernel Hacks

포토로그 Kernel Crash

통계 위젯 (화이트)


[LinuxKernel] What is process? 4. 프로세스(Process) 관리

Many software engineers said it is difficult to understand what the process is doing exactly. Because they study the process in a way that only understands the theory. But, it is hard to learn process in that way. We need to learn the process by analyzing the data structure or ftrace log related to the process as practical approach.

This chapter explains the process by looking at ftrace and Linux kernel codes using the raspberry pi. 
If you have a raspberry pi, we recommend you to practice yourself by typying the commands or analyzing ftrace logs introduced in this chapter.

The "operating system" book usually introduce the process at the first chapter, which is the same for "Linux Kernel" book.
In this section, we'll explore what a process is and look at tasks and threads. First, let's learn the what the process is.

The terminololy of 'process' has abstract and multiple meanings, so you can view what a process is from various perspectives.
What is a process? It refers to a program that is running in Linux system memory. It is also used similarly to the task to be scheduled. The technique of running several processes at the same time is called multi-processing, and the method of executing multiple programs simultaneously is called multitasking.

Let's take smartphone we are using for example. You can take notes on the phone while talking and use web browser listening to music. Multiple applications run simultaneously. This is possible because the program is running on the system at very rapid intervals through multitasking.

As for Linux developers, what is the process?  A process is an state of execution loaded into Linux system memory to wait for to be executed. This immediately raises the question listed below.

   ❑ If the process is waiting to be executed, what process will it go through when it is executed?
   ❑ What structure manage and identy the process?

The task descriptor is data structures and objects that manage processes represented by task_struct. This data structure contains elements such as the memory resource used by the process, the process name, execution time, process ID (PID), and the top address of the process stack.


If so, can you describe the process only as a task_structure? We previously defined a process as the execution flow itself. In which structure can the execution flow of the process be stored? You can answer this question as follows:

   ❑ Another important space for expressing a process's execution flow is the process stack space, which has a thread_info at the top address of the process stack.

Then, let's look at the execution flow of the next function and learn about the execution flow of the process.


If you look at the above list of functions for the first time, it may be unfamiliar, but if you look at them step by step, it won't be too difficult. The execution flow of this function tells you the following:

   ❑ Function call direction is from line 004 to line 000.
   ❑ When sigtimedwait() is called from a user space program, the corresponding system call handler function sys_rt_sigtimedwait() function is called.
   ❑ The __schedule() function on line 000 is called and scheduled.

The process executes the function while calling the function. So what resources do they use when calling and executing functions? This is the memory space of the process stack. When all processes are executed in kernel space, they each have a stack space assigned to them and run a function within the stack space.
Let's say that the process you saw earlier is run again by the scheduler. How does it work after that?


It will return from line 000 function to line function 004. Then, what kind of information do we refer to here to go back to the function that was previously executed?

The register set and execution flow that the process last executed were stored in the process stack space. Let's say you have written code that calls the B() function from the A() function, and the C() function from the B() function. When the C() function finishes execution, it returns from the B() function to the A() function. That's how it works.

In summary, the process implies a somewhat abstract concept However, the Linux kernel has the following data structures to express the process:

   ❑ task_struct structure: task descriptor
   ❑ thread_info structure: process thread information

People who start studying the process often ask, "What do I need to know if I know the process well?" To know what a process is very well, you need to be familiar with the process property information introduced earlier and the structure that stores the execution flow. This is because the functions that control the process are executed around the above structure.

In the next section, we'll look at tasks that are often used with processes.


댓글 입력 영역