Managing Solaris OS System Processes
Covered in this chapter:
- Conditions of a process in Solaris
- Different states of a process
- Process context information
- Different commands and utilities present for monitoring and controlling the system processes in Solaris
- Process Manager utility for monitoring, controlling, and scheduling the system processes in Solaris
The process is one of the fundamental abstractions of Unix. In Unix, every object is represented as either a file or a process. With the introduction of the /proc structure, there has been an effort to represent even processes as files.
A process is an instance of a running program or a program in execution. It can be any task that has an address space, executes its own piece of code, and has a unique process ID (PID). A process can create another process called a child process. Any process that creates the child process is called the parent process. This creation of new processes from existing parent processes is called forking (after the C function called fork()). Most processes in the system are created by fork system calls. The fork system call causes the current process to be split into two processes: a parent process and a child process. The child process continues to execute on the CPU until it completes. On completion, the child process returns to the system any resources that it used during its execution. While the child process is running, the parent process either waits for the child process to complete or continues to execute. If the parent process continues to execute, it periodically checks for the completion of the child process.
Running multiple processes has an impact on system performance because the processes consume system resources, such as memory and processor time, and some processes may even cause the system to hang. Managing processes becomes important in a multiuser environment such as Solaris. Managing processes involves monitoring the processes, finding the resource usage, finding the parent processes that have created child processes, assigning priority for processes, scheduling processes, and terminating processes.
From a system administrator perspective there are three broad categories of tasks associated with the management of the systems processes:
- Monitoring the processes
- - Viewing the PID, UID, and PPID
- - Viewing the priority of the process
- - Viewing the resource usage (in terms of memory and processor utilization)
- - Viewing the state of the process, etc.
- Controlling the processes
- - Using signals
- - Assigning the priority to the processes
- Scheduling the processes
6.1.1 State of a Process
A process undergoes many changes during its lifetime. For example, if a parent process waits for the child process to complete execution, the parent process puts itself in sleep state. Such a change from one state to another state is known as context switching. During its lifetime a process can exist in any of these four states: Ready or Runnable, Running, Sleep, and Zombie. A runnable process is ready to execute whenever CPU time is available. It has acquired all the resources it needs and is just waiting for the CPU to become available. If the process is in the Run state, it means that the process is running on the CPU. In the Sleep state, the process waits for a child process to complete or waits for a resource to become available. Zombie is the phase in which the child process terminates, but its entry is not removed from the process table until the parent process acknowledges the death of the child process by executing wait() or waitpid() system call. In this case, the child process is said to be in a Zombie state. Zombie processes are also called as defunct processes.
6.1.2 Process Context
Solaris is a multitasking, multiprocessing operating system, in which a number of programs run at the same time. A program can be made up of many processes. A process is a part of a program running in its own address space. This means that many users can be active on the system at the same time, running many processes simultaneously. But only one process is active per processor at any given time while the other processes wait in a job queue. Because each process takes its turn running in very short time slices (much less than a second each), multitasking operating systems give the illusion that multiple processes are running at the same time.
Each time a process is removed from access to the processor, sufficient information on its current operating state must be stored such that when it is again scheduled to run on the processor it can resume its operation from an identical position. This operational state data is known as its context and the act of removing the process's thread of execution from the processor (and replacing it with another) is known as a process switch or context switch.
The context of a process includes the following operational state data:
- Register set image
- - Program counter: address of the next instruction
- - Stack pointer: address of the last element on the stack
- - Processor status word: information about system state, with bits devoted to things like execution modes, interrupt priority levels, overflow bits, carry bits, etc.
- - Memory management registers: Mapping of the address translation tables of the process
- - Floating point unit registers
- User address space
- - Program text, data, user stack, shared memory regions, etc.
- Control information
- - u-area (user area), proc structure, kernel stack, address translation maps
- - User and group IDs (real and effective)
- Environment variables
- - Strings of the form variable = value
The u area includes the following:
- Process control block (PCB)
- Pointer to the proc structure
- Real/effective UID/GID
- Information regarding the current system call
- Signal handlers
- Memory management information (text, data, stack sizes)
- Table of open file descriptors
- Pointers to the current directory vnode and the controlling terminal vnode
- CPU usage statistics
- Resource limitations (disk quotas, etc.)
The proc structure includes the following:
- Identification: process ID and session ID
- Kernel address map location
- Current process state
- Pointers linking the process to a scheduler queue or sleep queue
- Pointers linking the process to lists of active, free, or zombie processes.
- Pointers keeping the structure in a hash queue based on PID
- Sleep channel (if the process is blocked)
- Scheduling priority
- Signal handling information
- Memory management information
- Information on the relationship of this process and other processes
All of the information needed to keep track of a process when switching is kept in a data package called a process control block (PCB). The process control block typically contains:
- Process ID (PID)
- Pointers to the locations in the program and its data where processing last occurred
- Register contents
- States of various flags and switches
- Memory information
- A list of files opened by the process
- The priority of the process
- The status of all I/O devices needed by the process
The new process is moved to the CPU by copying the PCB information into the appropriate locations (e.g., the program counter is loaded with the address of the next instruction to execute).