Fact-checked by Grok 2 weeks ago

Process group

In POSIX-conformant operating systems, a process group is a collection of one or more es that share a common process group identifier (PGID), enabling related processes to be signaled collectively. Each belongs to exactly one process group, identified by a positive PGID, and a newly created inherits the PGID of its by default. The process group leader is the whose PID equals the PGID. The leader may exit before other members, leaving the group leaderless. Process groups play a central role in job control and , particularly for handling signals such as SIGINT () or (hangup), which can be directed to an entire group rather than individual processes. In shells, they organize commands like (e.g., ls | wc), where all processes in the pipeline form a single group to allow unified suspension, resumption, or termination via terminal input sequences like Ctrl-C. Functions like setpgid() and getpgrp() are used to manage process group membership. Process groups are further organized into sessions, which are collections of one or more process groups established for job control and tied to a controlling . Within a session, only one process group can be the foreground process group, granting its members privileged access to the terminal for input and output, while background groups are restricted and may receive signals like SIGTTIN or SIGTTOU upon attempting terminal access. This structure supports features like job suspension (Ctrl-Z) and resumption (fg or bg commands), enhancing multitasking in interactive environments.

Definition and Basics

Definition

A process group is a collection of one or more related processes in an operating system that share the same process group identifier (PGID), a unique positive integer assigned to the group during its lifetime. This identifier enables the system to treat the processes as a cohesive unit, distinct from their individual process identifiers (PIDs). Each process belongs to exactly one process group, and newly created processes inherit the PGID of their parent unless explicitly reassigned. The primary purpose of a process group is to facilitate collective management of related es, particularly by allowing signals and other operations to be directed to all members simultaneously. This supports coordinated control, such as suspending or terminating an entire group in response to input, without needing to address each process individually. Unlike managing single processes, which operate independently, process groups enable job-like behavior—treating multiple cooperating tasks as a single entity—without requiring direct mechanisms like or . Process groups form part of a broader , where multiple groups can belong to a single session, a higher-level for related activities. A representative example is a shell command like [cc](/page/CC) -c foo.c, which spawns multiple processes (, , assembler) that join the same process group, allowing them to be controlled together, such as by interrupting the entire compilation with Ctrl+C.

Key Attributes

A process group is identified by a unique positive known as the process group ID (PGID), which remains associated with the group throughout its lifetime and is not reused by the system until the group ceases to exist. By convention, the PGID is typically set to the process ID () of the process group leader, defined as the process whose PID equals the group's PGID. Processes become members of a process group either upon creation, by inheriting the PGID of their parent process during a operation, or through explicit reassignment to another existing group within the same session. This inheritance ensures that child processes start in the same group as their creator, and the PGID is preserved even after an execve call replaces the process image. Process groups exhibit mutability in their composition: they can be created when a process sets its own PGID to match its , allowing it to become the leader of a new group, or processes can join an existing group via reassignment functions, provided the target group belongs to the same session. A group dissolves implicitly when its last member process terminates. The scope of a process group is confined to a single session, meaning all member processes must belong to the same session and cannot be reassigned across session boundaries, which enforces isolation for job control and . This limitation ensures that PGIDs are used effectively for targeted operations, such as delivering signals to all processes within the group.

Hierarchy and Relationships

Relation to Processes and Sessions

In Unix-like systems adhering to the POSIX standard, each process belongs to exactly one process group, forming a fundamental layer in the process hierarchy that enables coordinated management of related processes. A process group is defined as a collection of processes sharing the same process group ID (PGID), which serves as a unique identifier within the system. Upon creation via the fork() system call, a child process inherits the PGID of its parent, ensuring it initially joins the parent's process group. Sessions provide a higher-level in this hierarchy, encompassing one or more groups that share a common (SID). A is established for job control purposes and typically includes a controlling accessible only to within it, preventing groups from crossing session boundaries. All members of a given group are inherently part of the same , creating a two-level structure where individual are nested within groups, and groups are nested within . New inherit their membership from the creating , maintaining this organizational integrity. This hierarchical arrangement supports job control by allowing multiple process groups within a single session to operate as distinct foreground or background jobs. The foreground process group gains exclusive access to the session's controlling , while background groups are restricted to prevent interference, facilitating features like job suspension and resumption. In practice, this structure is evident in interactive environments, where each of commands (e.g., [ls](/page/Ls) | [grep](/page/Grep) pattern) or subshell execution forms a separate process group within the shell's session, enabling independent job without affecting the entire session.

Process Group Leader and ID

In POSIX-compliant systems, the process group leader is defined as the process whose process ID () equals the process group ID (PGID), typically the initial process that creates the group. This leader process serves as the identifier for the group and coordinates its lifecycle, including the addition of member processes through mechanisms like inheritance or explicit assignment. The leader's role is integral to job control operations, such as signaling and foreground/ , though it holds no elevated privileges over other group members. The PGID is assigned as the PID of the process group leader at the time of group creation, establishing a unique positive integer that identifies the group throughout its existence. Subsequent processes join the group either by inheriting the PGID from their parent during creation or through explicit reassignment, ensuring all members share the same identifier within the session. This assignment convention maintains consistency, as the PGID remains tied to the original leader's even as the group evolves. Upon termination of the process group leader, the group does not dissolve and continues to exist until its last member process exits or leaves via reassignment. No automatic selection of a new leader occurs; the PGID persists as the original value, and the group retains its identity without a living process holding that specific . The process group lifetime, which spans from creation to the departure of all members, underscores this persistence. PGIDs must be unique system-wide to prevent conflicts in job control and signaling, but they become available for reuse once the associated process group's lifetime ends. This system-wide scoping ensures that multiple process groups can coexist, including within a single session, without identifier overlap during active periods.

Implementation

In POSIX and Unix-like Systems

In POSIX-compliant systems, a group is defined as a collection of one or more processes that share the same group ID (PGID), which serves as a unique identifier for the group within the session. The POSIX.1 standard (IEEE Std 1003.1) mandates support for groups, including the ability to query the PGID of a via functions like getpgid(), create or join groups using setpgid(), and broadcast signals to all members of a group, such as through kill() with a negative PGID argument. This mechanism enables coordinated control of related processes, particularly for job control and signaling, without altering the fundamental model. In operating systems such as , BSD variants, and , process groups are implemented at the level to enforce session-based organization and isolation. In the , process groups are managed through the struct pid , which encapsulates identifiers for tasks, groups, and sessions, allowing the to track membership and propagate signals efficiently across group members. , a BSD , inherits process group semantics from early Unix, where each structure includes a PGID field inherited from the , enabling access control and signal distribution to grouped processes for job . Similarly, in , the maintains process group linkages within session structures to support event notification chains, particularly for signals and interactions, ensuring that grouped processes operate cohesively under a shared controlling . Key constraints in and implementations prevent cross-session intermingling: a can only join or create a process group within its own session, as setpgid() restricts the target PGID to values valid in the current session, and processes from different sessions cannot share a PGID. Additionally, each session associates with at most one controlling , limiting input/ to a single foreground process group while background groups face restrictions on interactive access to avoid interference. Modern extensions in integrate process groups with namespaces, particularly the PID namespace, which isolates PGIDs and process visibility within containerized environments like , allowing independent group management per namespace without altering core mechanics such as signal broadcasting or session isolation. This enhances scalability in virtualized setups while preserving the original group semantics for job control.

Equivalents in Non-POSIX Systems

In Windows operating systems, job objects serve as an analogous mechanism to process groups, enabling the management of multiple processes as a single unit for enforcing resource limits, such as working set size and process priority, and for coordinated termination. Job objects are created using the CreateJobObject function and processes are assigned to them via AssignProcessToJobObject, allowing control over attributes like security descriptors and limits that affect all associated processes. Unlike Unix process groups, which primarily facilitate signal broadcasting to all members, Windows job objects lack native support for direct signal distribution and instead emphasize resource containment and termination policies, such as killing all processes upon job closure. In operating systems (RTOS) outside strict compliance, equivalents vary. QNX, while POSIX-like due to its architecture, supports groups as part of its process management, where the procnto manager handles attributes including process IDs and groups for creation, destruction, and control. It also provides application groups to aggregate processes for unified control and isolation. In contrast, VxWorks primarily operates with tasks as the basic execution units rather than traditional processes, lacking native groups; instead, it relies on custom mechanisms like VxPOD for grouping and isolating subsystems through allocation of , time windows, and system objects. Non-POSIX systems generally prioritize resource control and security isolation over signal handling in their grouping constructs; for instance, Windows job objects establish security boundaries and limit resource usage across processes without the broadcast semantics central to Unix process groups. Cross-platform libraries such as emulate Unix process groups on Windows by providing a POSIX-compatible layer through its DLL, enabling , and group management behaviors on top of the Windows .

Uses and Applications

Signal Delivery

In operating systems conforming to , process groups facilitate the delivery of signals to multiple related processes simultaneously, enabling coordinated control such as interruption or termination of job pipelines. The kill() sends a signal to an entire process group by specifying a negative process group ID (PGID) as the pid argument, where the absolute value of pid identifies the target group; for example, kill(-PGID, sig) broadcasts the signal to all member processes for which the sender has permission. This mechanism is particularly useful for signals like SIGINT, which is generated by the driver upon receiving the INTR character (typically Ctrl+C) and delivered to all processes in the foreground process group associated with the controlling , provided the ISIG is set in the terminal attributes. A key arises in interactions, where the foreground process group ensures that user-initiated interrupts affect an entire command or job, such as a shell pipeline, rather than isolated processes. This targeted broadcasting prevents scenarios where child processes might otherwise evade signals intended for the group, maintaining orderly job execution. Additionally, in the context of orphaned process groups—those whose session leader has terminated—the kernel automatically sends a signal to all members upon certain events, like closure, compelling cleanup and preventing detached processes from persisting without access to the controlling . Exceptions apply to certain signals that can be directed to process groups via the same kill(-PGID, sig) syntax, notably SIGKILL, which unconditionally terminates all group members, and SIGSTOP, which suspends them; unlike most signals, these cannot be caught, blocked, or ignored by the recipients. Delivery order within the group is implementation-defined and not guaranteed by , though signals are sent to each eligible process individually after permission checks. Security restrictions ensure controlled access: a process may only signal a foreign process group if it possesses superuser privileges or if its effective or real user ID matches the real or saved set-user-ID of each target process in the group. No such user ID verification occurs for SIGCONT within the same session, allowing resumption of stopped processes without additional checks.

Job Control and Management

In Unix-like operating systems, job control refers to the mechanisms that enable a shell to manage multiple concurrent jobs, where each job consists of one or more related processes grouped into a process group. This allows users to execute commands in the foreground, suspending or terminating them as needed, while running other commands in the background without interrupting the primary interaction. The shell assigns a unique process group to each job, facilitating collective operations such as signal delivery to all member processes. A aspect of job is the distinction between foreground and jobs within a session tied to a controlling . The foreground process group receives exclusive access to the terminal for input and output, while groups are restricted to prevent interference; attempts by processes to read from the terminal the SIGTTIN signal, typically stopping the process, and writes may SIGTTOU if the terminal is in TOSTOP mode. This enforcement is handled by the terminal driver, ensuring that only the foreground job can interact directly with the user. Shell utilities like fg (foreground) and bg () manipulate these assignments by changing the foreground process group via system calls such as tcsetpgrp(), which sets the terminal's foreground group ID to that of the target process group. Job management also involves monitoring and controlling job states, including running, stopped, or completed. The shell tracks these via the jobs utility, which reports the status of all active jobs in the current session, displaying process group leaders and their conditions (e.g., "Running" or "Stopped"). Signals like SIGINT (from Ctrl+C) or SIGTSTP (from Ctrl+Z) are directed to the entire foreground process group, allowing unified suspension or termination. Orphaned process groups—those whose session leader has terminated—receive special handling, such as ignoring certain job control signals to prevent indefinite stops. This framework, defined in POSIX.1, supports interactive shells in multitasking environments by integrating process groups with terminal I/O and signal protocols.

System Calls and APIs

Creating and Managing Groups

In POSIX-compliant systems, process groups are created and managed primarily through the setpgid() and setsid() system calls, which allow processes to join existing groups, form new ones, or establish sessions with dedicated process groups. The setpgid() function assigns a process to a specified process group ID (PGID) within the same session, enabling either the joining of an existing group or the creation of a new one if the PGID matches the (PID) of the target . This call is typically invoked by implementations, such as those for job control, before executing a new program via exec() to ensure the child process inherits the desired group membership. However, setpgid() fails if the target process is a child of the caller that has already executed an exec() function, preventing group changes after the process image is replaced. The setsid() function creates a new session and simultaneously establishes a new within that session, with the calling process becoming the leader of both. It succeeds only if the caller is not already a process group leader, ensuring no overlap with existing groups, and detaches the process from any controlling terminal. This mechanism is essential for daemon processes or background jobs that require isolation from the parent's session. Additional process groups can then be formed within the new session using setpgid(). For retrieving the PGID of the calling process during management operations, the POSIX getpgrp() function provides a simple interface equivalent to getpgid(0), returning the current process group's ID without arguments. This call always succeeds and aids in verifying group assignments before further modifications. Process groups are implicitly managed by the kernel and dissolve automatically when the last member process terminates, as there is no explicit system call to delete a group. Once empty, the PGID becomes available for reuse, maintaining system efficiency without manual intervention.

Querying Group Information

Process group information can be queried using specific system calls in POSIX-compliant systems, allowing applications and administrators to retrieve details about process affiliations without altering the group structure. These functions provide essential data for understanding process hierarchies, particularly in multi-process environments where coordination is key. The getpgid() function retrieves the process group ID (PGID) of a specified process identified by its process ID (pid); if pid is zero, it returns the PGID of the calling process itself. This function is useful for determining group membership across related processes, returning -1 on error with errno set to indicate the failure reason, such as if the process does not exist. For terminal-related queries, the tcgetpgrp() function obtains the PGID of the foreground process group associated with a controlling terminal specified by file descriptor fd. It returns this PGID value directly or -1 on error, enabling processes—even those in background groups—to check the current foreground status without permission restrictions beyond file access. Related to process groups, the getsid() function retrieves the session ID of the process specified by pid, which is the PGID of the session leader process containing the target; if pid is zero, it returns the session ID of the calling process. This provides context on broader session containment, as detailed in the relation to processes and sessions. In and system monitoring, these query functions underpin tools like the ps command, which displays PGID alongside other process details when invoked with options such as -o pid,pgid or the BSD-style j format, facilitating the visualization of process group hierarchies for troubleshooting and resource management.

History and Evolution

Origins in Early Unix

Process groups were first introduced in the Fourth Edition of Unix, released in November 1973 by , primarily as a mechanism for basic grouping of processes associated with a controlling . In this early implementation, every process belonged to a process group tied directly to its (tty), facilitating the delivery of signals such as SIGINT (from ) and SIGQUIT (from quit) to all processes in the group when generated at the . This design addressed the need for coordinated signal handling in a multi-process , where processes from the same command could be managed collectively without individual addressing. The concept was significantly expanded in Version 7 Unix, released in 1979, where process groups gained an independent identity with their own numeric ID (via the p_pgrp field), separate from the terminal association. The setpgrp() system call to explicitly set a process's group ID was introduced later in AT&T System III Unix in 1981. Developed by Ken Thompson and Dennis Ritchie at Bell Labs, process groups in Version 7 featured "closed" semantics, meaning processes could not easily leave their group once assigned, which simplified management but limited flexibility. The initial purpose centered on managing related processes spawned from shell commands, particularly to prevent signal loss in pipelines—sequences of commands connected by pipes where output from one process feeds into the next—ensuring that terminal-generated signals reached all pipeline participants reliably. Prior to enhancements in Berkeley Software Distribution (BSD) variants, process groups in these early Unix versions were limited to serving as a simple collection of processes without advanced job control features, such as suspending or resuming groups. This basic functionality sufficed for the era's primarily sequential and pipeline-based workflows at Bell Labs.

Key Developments

In the 1980s, Berkeley Software Distribution (BSD) introduced significant extensions to process group functionality, particularly through the development of job control mechanisms. The 4.2BSD release in 1983 marked a key milestone by integrating job control features originally prototyped in 4.1BSD, allowing processes to be organized into groups for foreground and background execution under shells like csh. This enabled users to suspend, resume, and manage related processes as cohesive units, with the process group ID (PGID) serving as the identifier for job-level operations, such as signal delivery to all members. These enhancements built on earlier Unix concepts but provided a more robust framework for interactive computing environments. The standardization of process groups came with the IEEE POSIX.1-1988 specification, which formalized key elements including the PGID, the setsid() function for creating new sessions and groups, and precise signal semantics for group-wide delivery. POSIX.1 defined groups as collections of one or more es that could receive signals collectively, with the group leader typically identified by the PGID matching its ID, ensuring portability across systems. This standard influenced subsequent Unix variants, including System V Release 4 (SVR4) in 1988, which adopted POSIX-compliant group APIs to enhance interoperability while incorporating BSD-inspired job control. Linux inherited the traditional process group model directly from Unix and BSD traditions, maintaining compatibility with POSIX semantics for signal handling and job management since its early kernels. In the 2000s, Linux extended process organization through the introduction of control groups (cgroups), developed primarily by Paul Menage and Rohit Seth at , with initial work beginning in 2006 and merger into the mainline kernel in version 2.6.24 (2007). Unlike traditional process groups focused on signaling, cgroups provide hierarchical resource control—limiting CPU, memory, and I/O for groups of processes—without altering core signal semantics, thus serving complementary roles in modern system administration. In recent developments, process groups have been enhanced within technologies, where PID namespaces isolate process identifiers and group structures to prevent cross-container interference. For instance, leverages PID namespaces to confine process groups within containers, allowing each to maintain its own independent view of processes while adhering to host-level resource limits via . The core POSIX-defined process group mechanisms have remained largely unchanged since 1988, with evolutions primarily in integration with isolation primitives rather than fundamental alterations.

References

  1. [1]
    Definitions - The Open Group Publications Catalog
    A file of a particular type that is used as a communications endpoint for process-to-process communication as described in the System Interfaces volume of POSIX ...
  2. [2]
    credentials(7) - Linux manual page - man7.org
    A process group (sometimes called a "job") is a collection of processes that share the same process group ID; the shell creates a new process group for the ...
  3. [3]
    4.8 Process Groups and Sessions - InformIT
    Oct 2, 2014 · A process group is a collection of related processes, while a session is a collection of process groups, and all members of a process group are ...
  4. [4]
    Concepts of Job Control (The GNU C Library)
    ### Summary of Process Group and Job Control Concepts (Unix/POSIX Context)
  5. [5]
    Definitions
    Summary of each segment:
  6. [6]
  7. [7]
  8. [8]
    setpgid(2) - Linux manual page - man7.org
    A child created via fork(2) inherits its parent's process group ID. The PGID is preserved across an execve(2). Each process group is a member of a session and ...Missing: definition attributes scope
  9. [9]
    setpgid
    ### Summary of Process Groups in setpgid()
  10. [10]
  11. [11]
  12. [12]
    getpgid
    The getpgid() function shall return the process group ID of the process whose process ID is equal to pid. If pid is equal to 0, getpgid() shall return the ...
  13. [13]
    2.4. Process Management - FreeBSD Documentation Archive
    Process groups are used to control access to terminals and to provide a means of distributing signals to collections of related processes. A process inherits ...
  14. [14]
    Control Groups - The Linux Kernel documentation
    Control Groups (cgroups) aggregate tasks into hierarchical groups with specialized behavior, associating tasks with parameters for subsystems.
  15. [15]
    Job Objects - Win32 apps - Microsoft Learn
    Jul 14, 2025 · A job object allows groups of processes to be managed as a unit. Job objects are namable, securable, sharable objects that control attributes of the processes ...
  16. [16]
    Very Confused why ProcessStartInfo.CreateNewProcessGroup is ...
    Windows job objects are closer equivalent. Process groups on Unix are used for resource control, they are more flexible, there is no handshake cooperation ...
  17. [17]
    Process management - QNX
    Process management consists of process creation and destruction and also management of process attributes such as process IDs, process groups, and user IDs.
  18. [18]
    Application groups - QNX
    Application groups are used to group processes together so they can be controlled as a group. Application groups rely on every process having its own ID.
  19. [19]
    Software Containment in VxWorks: VxPOD – A Separation ...
    Nov 30, 2016 · By allotting memory, time window, system objects, file systems, and system calls to specific process groups, VxWorks isolates each sub-system ...
  20. [20]
    [PDF] Cygwin User's Guide
    Cygwin is a Linux-like environment for Windows. It consists of a DLL (cygwin1.dll), which acts as an emulation layer providing substantial POSIX (Portable ...
  21. [21]
    kill
    The kill() function shall send a signal to a process or a group of processes specified by pid. The signal to be sent is specified by sig and is either one ...
  22. [22]
    Orphaned Process Groups (The GNU C Library)
    ### Summary of Orphaned Process Groups and Signal Handling
  23. [23]
    11. General Terminal Interface
    If HUPCL is set, the modem control lines for the port shall be lowered when the last process with the port open closes the port or the process terminates. The ...
  24. [24]
    jobs - The Open Group Publications Catalog
    The -p option is the only portable way to find out the process group of a job because different implementations have different strategies for defining the ...<|separator|>
  25. [25]
    setsid(2) - Linux manual page - man7.org
    setsid() creates a new session if the calling process is not a process group leader. The calling process is the leader of the new session.
  26. [26]
    tcgetpgrp
    The tcgetpgrp() function shall return the value of the process group ID of the foreground process group associated with the terminal.
  27. [27]
    getsid
    The getsid() function shall obtain the process group ID of the process that is the session leader of the process specified by pid.
  28. [28]
    ps(1) - Linux manual page - man7.org
    It displays the process ID (pid=PID), the terminal associated with the process (tname=TTY), the cumulated CPU time in [DD-]hh:mm:ss format (time=TIME), and the ...
  29. [29]
    Control groups, part 1: On the history of process grouping - LWN.net
    Jul 1, 2014 · To properly represent the groupings of processes relevant for a modern desktop, we really need a deeper hierarchy. One level would represent ...<|control11|><|separator|>
  30. [30]
    The history of sending signals to Unix process groups
    Sep 5, 2022 · All (Unix) processes are members of some process group. Process groups go very far back in Unix; they're present at least as far back as ...Missing: definition | Show results with:definition
  31. [31]
    Evolution of the Unix Time-sharing System - Nokia
    This paper presents a brief history of the early development of the Unix operating system. It concentrates on the evolution of the file system, the process- ...
  32. [32]
    setpgrp
    If the calling process is not already a session leader, setpgrp() sets the process group ID of the calling process to the process ID of the calling process.
  33. [33]
    [PDF] Changes to the Kernel in 4.2BSD July 25, 1983
    Jul 25, 1983 · This document summarizes the changes to the kernel between the September 1981 4.1BSD release and the July 1983 4.2BSD distribution.Missing: job introduction
  34. [34]
    [PDF] 4.2BSD and 4.3BSD as Examples of the UNIX System
    Jul 9, 1973 · In 4.2BSD, a user's processes may be in several groups simultaneously. ... C shell in job control to stop and restart a process. SIGILL is ...
  35. [35]
    [PDF] IEEE standard portable operating system interface for computer ...
    In its present form, the standard focuses primarily on the C Language inter¬ face to the operating system. IEEE Std 1003.1-1988 is the first of a group of ...
  36. [36]
    setpgid
    The setpgid() function shall either join an existing process group or create a new process group within the session of the calling process.
  37. [37]
    Understanding the new control groups API - LWN.net
    Mar 23, 2016 · The development of the Linux cgroup subsystem started in 2006 at Google, led primarily by Rohit Seth and Paul Menage. Initially the project ...Missing: introduction | Show results with:introduction
  38. [38]
    cgroups(7) - Linux manual page - man7.org
    Control groups, usually referred to as cgroups, are a Linux kernel feature which allow processes to be organized into hierarchical groups.
  39. [39]
    docker container run | Docker Docs
    Mar 4, 2015 · PID namespace provides separation of processes. The PID Namespace removes the view of the system processes, and allows process ids to be reused ...
  40. [40]
    Docker Engine security
    Namespaces provide the first and most straightforward form of isolation. Processes running within a container cannot see, and even less affect, processes ...Isolate containers with a user... · Seccomp security profiles · Rootless modeMissing: enhancements | Show results with:enhancements