Process Life Cycles Processes

Zombie — The process is trying to die; another common term is defunct. Swapped — The process is removed from the system main memory to a disk more precisely, a process image is removed. This occurs when the competition for memory is intense, a lack of available memory for new processes is obvious, and regular memory paging is unable to solve the problem efficiently. Strictly speaking, swapped is not a true process state, because a swapped process can be in one of the previously mentioned states: sleeping, stopped, or even runnable.

2.4.2 Process Life Cycles

Each process is living as long as the corresponding program is running. Process life cycles vary in range from extremely short up to indefinitely like for daemons or better to say as long as the system lives. Process starts with its creation and lasts until terminated program exit upon its completion or forced to quit. 2.4.2.1 Process Creation In UNIX a new process is created with the fork system call. An existing process, a parent process, makes a copy of itself into the address space of a child process. From the users point of view, the child process is an exact duplicate of the parent process, except for two values: the PID and the parent PID. The fork system call returns the child PID to the parent process and zero to the child process thus, a program can determine whether it is the parent or the child process. The fork system call involves three main steps: Allocating and initializing a new structure for the child process 1. Duplicating the context of the parent process for the child process 2. Scheduling the child process to run 3. The memory organization and layout associated with a UNIX process contains three memory segments called: Text segment 1. A shared read−only segment that includes program code Data segment 2. A private read−write segment divided into initialized and uninitialized data parts the uninitialized part is also known as block started symbol BSS Stack segment 3. A private read−write segment for system and process related data There are two modes of the fork operation: A process makes a copy of itself to handle another task; this is typical for network server daemons. 1. A process wants to execute another program. Since the only way to create a new process is through the fork operation, the process first makes a copy of itself and then the child process issues an exec system call to execute a new program. 2. 55 The ultimate ancestor for every process on a UNIX platform is the process with PID 1, named init and created by the system kernel during the boot procedure. The init process presents a starting point in the chain of process creations; it creates a number of other processes based on fork−and−exec. Among the many created processes are one or more getty processes, assigned to existing terminal lines. Their main duty is to keep the system from unauthorized login attempts; they protect the system from potential intruders, and from the damage they can cause to the system. This is illustrated in Figure 2.2. Different stages of the creation of involved processes are presented, assuming four existing terminal lines. Figure 2.2: UNIX process creation fork and exec. Four getty processes have been forked−and−exec by the init process. Each getty process is taking care of one terminal line. Since a user attempts to access the system via a terminal line more precisely via an attached terminal, getty will exec another program login to supply a login prompt, and to authenticate the user it will look up the users login and password data in the file etcpasswd; this is shown in the figure for the second terminal line. Upon login, it checks the 56 2.4.2.2 Process Termination A process terminates either voluntarily through an exit system call, or involuntarily as the result of a received signal. In either case, termination of a process causes a status code to be returned to its parent process. The process then cleans and closes all process−related resources: It cancels any pending timers. • It releases virtual memory resources. • It closes open descriptors. • It handles stopped or traced child processes. • After completing those tasks the process can die, i.e., it can be deleted from the kernel process table.

2.4.3 Process Handling