HPlogo HP-UX Process Management: White Paper > Chapter 1 Process Management

What is a process?

» 

Technical documentation

Complete book in PDF

 » Table of Contents

A process is a running program, managed by such system components as the scheduler and the memory management subsystem. Described most simply, a process is a container for a set of instructions that carry out the overall task of a program.

A process consists of text (the code that the process runs), data (used by the code), and stack (temporary data storage for when the process is running). These and other elements are known as the process context.

NOTE: HP-UX is now a threads-based operating system. This affects how we view processes.

Every process has at least one thread. Think of a process as a container for groups of threads. A process holds the address space and shared resources for all the threads in a program in one place. When you manipulate the elements of a program (things you schedule, context switches, and so forth), you always manipulate threads.

Two stacks are associated with a process, kernel stack and user stack. The process uses the user stack when in user space and the kernel stack when in kernel space.

Although processes appear to the user to run simultaneously, in fact a single processor is executing only one process at any given instant.

A process's proc structure includes:

  • The program's kernel data structures (variables, arrays, records) .

  • Process ID, parent process ID, process group ID.

  • Process user and group IDs (both real and effective IDs).

  • Group access list.

  • Information on the process's open files.

  • Process's current working directory.

  • Audit ID (on trusted systems only).

Process Relationships

Processes maintain hierarchical, parent-child relationships. Every process has one parent, but a parent process can have many child processes. Processes can create processes, which in turn, can create more processes.

A child process inherits its parent's environment (including environment variables, current working directory, open files). Also, all processes except system processes (such as init, pagedaemon, and sched (the "swapper")) belong to process groups, which are explained shortly.

Process and Parent Process IDs

When a process is created, HP-UX assigns the process a unique integer number known as a process ID (PID). The HP-UX kernel identifies each process by its process ID when executing commands and system calls.

A process also has a parent process ID (PPID), which is the PID of the parent process. You can see the PIDs and PPIDs of processes currently running on your system by using the ps command.

User and Group IDs (Real and Effective)

In addition to the process ID, a process has other identification numbers:

  • real user ID

  • real group ID

  • effective user ID

  • effective group ID.

Real user ID is an integer value that identifies the owner of the process -- that is, the user ID of the user who invoked the process. Real group ID is an integer value that identifies the group to which the user belongs. The real group ID is shared by all users who belong to the group. It allows members of the same group to share files, and to disallow access to users who do not belong to the group.

The id command displays both integers and names associated with real user ID and real group ID. The /etc/passwd file assigns the real user ID and real group ID to the user at login.

The effective user ID and effective group ID allow a process running a program to act as the program's owner while the program executes. The effective IDs are usually identical to the user's real IDs. However, the effective user ID and group ID can be set (setuid and setgid) individually to allow limited superuser capability, by making the effective IDs of the program's processes equal to the real IDs of the program's owner. The classic example is passwd, which allows limited ability to change /etc/passwd.

The effective IDs are used to allow a user to access or modify a data file or to execute a program in a limited manner. When the effective user ID is zero, the user is allowed to execute system calls as superuser.

The effective user and group IDs remain set until:

  • The process terminates.

  • The effective IDs are reset by an overlaying process, if the setuid or setgid bit is set (see exec(2)).

  • The effective, real, and saved IDs are reset by the system calls setuid, setgid, setresuid, or setresgid.

In a trusted system, each user has an audit ID that does not change, even when the user executes programs using a different effective user ID.

Process Context

The context of a process includes its component parts and kernel resources, as detailed in the following table. Note, however, that some of these elements are now defined in terms of threads.

Table 1-1 Context of a process

TypePurpose
textMachine/program code that is executed. Maximum size of text is limited by the maxtsiz configurable parameter.
DataInitialized data that accompanies the text. Contains the global variables used by the program. Maximum size of data is limited by the maxdsiz configurable parameter.
bssUninitialized data
heap spaceUndefined space available to the process as by a call to malloc(3) function.
private memory mapped files (mmap)mmap files allow applications to map file data into a process's virtual address space.
user and kernel stacksUser stack is used while a thread is executing in user mode to store variables, subroutines; used for function calls in the user program. Maximum size of the process's user stack is limited by maxssiz configurable parameter.The kernel stack is used for function calls when the process executes system calls, etc.
user structure (uarea)Per-process information needed when the process is running (and thus can be paged out). Points to process register state, open file descriptors, open devices, system call arguments and return values. Since HP-UX is a threads-based kernel, it has one user structure for each thread structure; each kernel thread has its own uarea.
shared librariesUsed by processes to reduce the amount of memory consumed. Shared library functions are mapped into processes.
shared memoryAvailable range of addresses that are allocated using the shared memory interfaces and that enable processes to share address space. Useful for communicating between processes.
process structureRemains memory resident. Contains per-process information needed to schedule threads. Includes process ID, scheduling priority, run state, signal mask.
register contextRegister values and program counter. When a process is running, reg. context is loaded in CPU registers; when not running, register context is stored in the process control block (pcb). Register context is now thread context.
virtual address spaceA four-gigabyte (32-bit) range of addresses into which the context of a process is logically mapped.