Process identifier
This article needs additional citations for verification. (October 2017) |
In
Unix-like
In
There are two tasks with specially distinguished process IDs: PID 0 is used for swapper or sched, which is part of the kernel and is a process that runs on a CPU core whenever that CPU core has nothing else to do.[1] Linux also calls the threads of this process idle tasks.[2] In some APIs, PID 0 is also used as a special value that always refers to the calling thread, process, or process group.[3][4] Process ID 1 is usually the init process primarily responsible for starting and shutting down the system. Originally, process ID 1 was not specifically reserved for init by any technical measures: it simply had this ID as a natural consequence of being the first process invoked by the kernel. More recent Unix systems typically have additional kernel components visible as 'processes', in which case PID 1 is actively reserved for the init process to maintain consistency with older systems.
Process IDs, in the first place, are usually allocated on a sequential basis[5], beginning at 0 and rising to a maximum value which varies from system to system. Once this limit is reached, allocation restarts at 300 and again increases. In macOS and HP-UX, allocation restarts at 100. However, for this and subsequent passes any PIDs still assigned to processes are skipped. Some consider this to be a potential security vulnerability in that it allows information about the system to be extracted, or messages to be covertly passed between processes. As such, implementations that are particularly concerned about security may choose a different method of PID assignment.[6] On some systems, like MPE/iX, the lowest available PID is used, sometimes in an effort to minimize the number of process information kernel pages in memory.
The current process ID is provided by a getpid()
system call[7], or as a variable $$
in shell. The process ID of a parent process is obtainable by a getppid()
system call.[8]
On Linux, the maximum process ID is given by the pseudo-file /proc/sys/kernel/pid_max
.[9]
Pidfile
Some processes, for example, the
Microsoft Windows
On the
See also
- User identifier (UID)
- Group identifier (GID)
- Handle (computing)
- Program Segment Prefix (PSP)
References
- ^ What is PID 0?
- ^ Linux kernel code: tools/perf/builtin-sched.c,
pid 0 == swapper == idle task
- ^ kill(2) — Linux manual page
- ^ sched_setscheduler(2) — Linux manual page
- ^ pid_namespaces(7) — Linux manual page
- ^ comp.unix.aix Frequently Asked Questions, retrieved 2008-07-21
- ^ "getpid", The Open Group Base Specifications Issue 7, 2018 edition
- ^ "getppid", The Open Group Base Specifications Issue 7, 2018 edition
- ^ "proc - process information pseudo-filesystem", Linux Programmer's Manual, retrieved 2009-12-28
- ^ "GetCurrentProcessId Function", Windows Dev Center, Microsoft, 5 December 2018
- ^ "GetProcessId function", Windows Dev Center, Microsoft, 5 December 2018
- ISBN 0-7356-1917-4
- ^ Chen, Raymond (2008-02-28), "Why are process and thread IDs multiples of four?", The Old New Thing, Microsoft