in order to differentiate each process in the Linux operating system, each process is assigned a unique process number, also known as the process ID. The process ID is stored in the process's PCB and belongs to the kernel resource of the process. the process ID of each process is unique, but the process ID can be reused, and when a process is terminated, all its resources are freed, including the process ID. When the system creates a new process again, it can be assigned a process ID that has already been disposed. Because the operating system employs a deferred reuse algorithm, the process ID assigned to the process that was just created is usually not the process ID that was just released. The process ID of some processes in the operating system is fixed, such as the process ID of the 0,init process for the scheduling process is 1. These processes are special processes. ======================================================================As mentioned earlier, the process ID is stored in the process's PCB and belongs to the kernel resource of the process, so it is not possible to get the process ID directly in the user space, and it must be obtained through the system call. Here are a few system callsfunction Prototypes:return Value:
- This function does not go wrong, it always returns process ID of the process
function Prototypes:return Value:
- The same error will always return the parent process ID of this process
function Prototypes:return Value:
- These two functions also do not go wrong, always returning the actual user ID of the process and the valid user ID of the process
Note: The process ID in these system calls uses the pid_t type, and the user ID uses the uid_t type. You should also use this type to define variables later when you write your program.
Process Control (ii)---process identifier