Make a little progress every day--learn more about Linux process IDs

Source: Internet
Author: User

Reprint Please specify source: http://blog.csdn.net/cywosp/article/details/38968011


1. OverviewAs is well known, a process is an instance of a running program, but in Linux the process can be rewritten again. A process is an abstract entity defined by the kernel and assigns the entity the system resources used to run the program.

From the kernel point of view. The process consists of a user memory space (User-space Memories) and a series of kernel data structures. The user memory space includes the program code and the variables used by the code, and the kernel data structure is used to maintain process state information.

The information recorded in the kernel data structure includes many process-related identification numbers (IDS), virtual memory tables, descriptive table of open files, information about signal transmission and processing, process resource usage and limitations, current working folders, and a large amount of other information.


2. Process descriptive narrator Each process has a process number (PID), which is a positive number that uniquely identifies a process in the system.

For various system calls, process numbers can sometimes be used as incoming parameters and sometimes as return values. Example. The system call Kill (() agrees that the caller sends a signal to the process that owns the particular process number. When you need to create a unique identifier for a process. The process number will come in handy. The common example is to use the process number as part of the process-related file name (the log file name).

Can be used in distributed systemsIp:port:start_time:pidTo differentiate the processes in the entire cluster. This will guarantee uniqueness altogether. can also be positioned at high speed after a problem.
system call Getpid () returns the process number of the calling process, declaring for example the following:#include<unistd.h>//Always successfully returns process ID of callerpid_t getpid (void);
3. System qualification of process descriptive descriptorsThe Linux kernel limit process number needs to be less than or equal to 32767. When a new process is created, the kernel assigns the next available process number to its use in order. Each time the process number reaches the 32767 limit, the kernel resets the process number counter so that it is assigned again from the beginning of the integer.

This assignment is detailed such as the following:     Once the process number reaches 32767. The kernel resets the process number counter to 300. Rather than 1. This is the reason. Because the process number of a low value is a long-term occupation of the system process and daemon, searching for unused process numbers in this range is only a waste of time.     The upper limit of the process number is 32767 in the Linux 2.4 and earlier versions, Defined by the kernel constant Pid_max. In the Linux 2.6 version number. The situation has changed. Although the default upper limit for process numbers is still 32767. However, it can be adjusted by the Linux system-specific/proc/sys/kernel/pid_max file (value = Max process +1). In 32-bit platforms, the maximum value of the Pid_max file is 32767, but it is in a 64-bit platform. The maximum value of the file can be as high as 2^22 (about 4 million), and the number of processes that the system can accommodate is huge.
4. Parent process number     each process has a parent process that creates its own.

Use System call Getppid () to get the process number of the parent process. The function declaration is as follows: #include<unistd.h> //Always successfully returns ID of the parent of caller pid_t getppid (void) in fact, the parent process number attribute of each process reflects a tree-like relationship between all processes on the system. The parent process of each parent process has its own parent process, and so on. Go back to process--init # 1th. That is the ancestor of all processes.

Use the Pstree command to view this tree relationship. assuming that the parent process of the child process terminates, the child process becomes "orphan", and the Init process will then adopt the process, and the child process may call the Getppid () back to process number 1. By viewing the Ppid field provided by the/proc/pid/status file that is unique to the Linux system, you can learn about the parent process of each process.






Make a little progress every day--learn more about Linux process IDs

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.