Make a little progress every day-re-recognize the process number in Linux and re-recognize yourself

Source: Internet
Author: User

Make a little progress every day-re-recognize the process number in Linux and re-recognize yourself

Reprint please explain the source: http://blog.csdn.net/cywosp/article/details/38968011


1. OverviewAs we all know, a process is an instance of an executable program. But in Linux, a process can be rewritten as an abstract entity defined by the kernel, and allocate various system resources for executing programs to the entity. From the kernel perspective, a process consists of user-space memory and a series of kernel data structures. The user memory space contains the variables used by program code and code, the kernel data structure is used to maintain the Process status information. The information recorded in the kernel data structure includes many process-related IDs) virtual Memory table, open file descriptor table, information about signal transmission and processing, process resource usage and restrictions, current working directory and a large amount of other information.
2. Process DescriptorEach process has a PID, which is a positive number used to uniquely identify a process in the system. For various system calls, process numbers can sometimes be used as input parameters, and sometimes as return values. For example, the system calls kill () to allow the caller to send a signal to a process with a specific process number. When you need to create a unique identifier for a process, the process number will come in handy. A common example is to use a process number as a part of the process-related file name (log file name ). Can be used in a distributed system Ip: port: start_time: pidTo distinguish the processes in the entire cluster, so that the uniqueness can be fully guaranteed, or the problem can be quickly located.
The system calls getpid () to return the process NUMBER of THE calling process. The declaration is as follows: # include <unistd. h> // Always successfully returns process ID of caller pid_t getpid ( Void);
3. System Restrictions on process DescriptorsThe Linux kernel's restricted process number must be less than or equal to 32767. When a new process is created, the kernel assigns the next available process number to it in order. Whenever the process number reaches the 32767 limit, the kernel resets the process number counter to re-allocate the number from an integer. The allocation method is as follows: once the process number reaches 32767, the kernel resets the process number counter to 300 instead of 1. This is because the low-value process numbers are used by system processes and daemon for a long time. Searching for unused process numbers within this range is only a waste of time. In Linux 2.4 and earlier versions, the maximum number of processes is 32767, defined by the kernel constant PID_MAX. In Linux 2.6, the situation has changed. Although the maximum number of processes is still 32767 by default, you can adjust it through the/proc/sys/kernel/pid_max file specific to the Linux system (value = maximum process + 1 ). On a 32-bit platform, the maximum value of the pid_max file is 32767. However, on a 64-bit platform, the maximum value of the file can be as high as 2 ^ 22 power (about 4 million ), the system can accommodate a large number of processes.
4. Parent process numberEach process has its own parent process. Call getppid () to obtain the process ID of the parent process. The function declaration is as follows: # include <unistd. h> // Always successfully returns ID of parent of caller pid_t getppid ( VoidIn fact, the parent process number attribute of each process reflects the tree relationship between all processes on the system. Each parent process has its own parent process, and so on, tracing back to process 1-init process, that is, the ancestor of all processes. Run the pstree command to view the tree relationship. If the parent process of the child process is terminated, the child process will become an orphan, and the init process will then adopt the process () will return process number 1. By viewing the PPid field provided by the/proc/PID/status file specific to the Linux system, you can know the parent process of each process.





In Linux, how does one find the corresponding process based on the process number!

Pe-eLf | grep PID
Or
Ls-l/proc/PID/exe.

In linux, how does one view any sub-process under a process number?

Ps-lax: View processes and parent processes. Find the pid of the process you want to view, and then

Ps -- ppid ****

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.