Contained Within
Find More Documentation
Featured Support Resources
| Descargar este libro en PDF
Managing Processes
7
- The processes running on a system consume the system's resources. You may be able to influence the performance of your system by controlling and monitoring the processes that the CPU is executing.
- This chapter describes how to monitor and manage processes running on your system. If you are familiar with the concepts of process control, use the following table to go directly to the step-by-step instructions.
-
Process Terminology
- The new structures and terms related to processes are described in Table 7-1.
-
Table 7-1
| Term | Description |
| process | An instance of program in execution. |
| lightweight process | Is a virtual CPU or execution resource. LWPs are scheduled by the kernel to use available CPU resources based on their scheduling class and priority. LWPs include a kernel thread, which contains information that has to be in memory all the time and an LWP, which contains information that is swappable. |
| application thread | A series of instructions with a separate stack that can execute independently in a user's address space. They can be multiplexed on top of LWPs. |
- A process can consist of multiple lightweight processes (LWPs), and multiple application threads. The kernel schedules a kernel-thread structure, which is the scheduling entity in the SunOS 5.x environment. The different process structures are described below.
-
| Structure | Description |
| proc | Contains information that pertains to the whole process and has to be in main memory all the time. |
| kthread | Contains information that pertains to one LWP and has to be in main memory all the time. |
| user | Contains the per process information that is swappable. |
| klwp | Contains the per LWP process information that is swappable. |
-
Figure 7-1 illustrates the relationship of these structures.
-
Figure 7-1 Process Structures
-

- Most process resources are accessible to all the threads in the process. Almost all process virtual memory is shared. A change in shared data by one thread is available to the other threads in the process.
About Monitoring Processes
The ps Command
- The ps command enables you to monitor the execution status (or process status) of the active processes on a system. Depending on which options you use, the command reports the following information:
-
- Current status of the process
- Process ID
- Parent process ID
- User ID
- Scheduling class
- Priority
- Address of the process
- Memory used
- CPU time used
-
Table 7-2 lists and describes the fields reported by ps. The fields displayed depend on which option you choose. See the reference page for ps(1) for a description of all the available options.
-
Table 7-2 ps
| Field | Description |
| F | Hexadecimal flags, which, added together, indicate the process's current state as follows:
00 The process has terminated.
01 The process is a system process and is always in memory. 02 The process is being traced by its parent. 04 The process is stopped.
08 The process cannot be awakened by a signal. 10 The process is currently in memory and is locked. 20 The process cannot be swapped.
|
| S | The current state of the process, as indicated by one of the following letters: O The process is currently running. S The process is sleeping; waiting for an I/O event to be completed. R The process is ready to run.
I The process is idle; it is being created. Z This is a zombie process; the process has terminated and the parent has not reaped its status.
T The process is stopped.
X The process is waiting for more memory.
|
| UID | The user ID of the process's owner. |
| PID | The process identification number. |
| PPID | The parent process's identification number. |
| C | The processor utilization for scheduling; this field is not displayed when the -c option is used. |
| CLS | The scheduling class to which the process belongs: real-time, system, or timesharing. This field is included only with the -c option. |
| PRI | The kernel thread's scheduling priority; higher numbers mean higher priority. |
| NI | The process's nice number, which contributes to its scheduling priority. Making a process nicer means lowering its priority. |
-
Table 7-2 ps
| Field | Description |
| ADDR | The address of the proc structure. |
| SZ | The virtual address size of process. |
| WCHAN | The address of an event or lock for which the process is sleeping. |
| STIME | The starting time of the process (in hours, minutes, and seconds). |
| TTY | The terminal from which the process (or its parent) was started. A question mark indicates there is no controlling terminal. |
| TIME | The total amount of CPU time used by the process since it began. |
| COMD | The command that generated the process. |
- Typing ps with no arguments shows you the processes associated with your login session:
-
mysys% /usr/bin/ps
PID TTY TIME COMD
1664 pts/4 0:06 csh
2081 pts/4 0:00 ps
|
- Typing ps -ef displays a full (-f) listing of all the processes being executed on the system (-e). The UID displays the login name of the user.
-
| mysys% ps | -ef |
|
|
|
|
|
|
| UID | PID | PPID | C | STIME | TTY | TIME | CMD |
| root | 0 | 0 | 80 | Jan 30 | ? | 0:02 | sched |
| root | 1 | 0 | 80 | Jan 30 | ? | 7:17 | /etc/init |
| root | 2 | 0 | 67 | Jan 30 | ? | 0:01 | pageout |
| root | 3 | 0 | 80 | Jan 30 | ? | 69.46 | fsflush |
| root | 123 | 1 | 80 | Jan 30 | ? | 0:12 | /usr/lib/saf/sac -t 300 |
| root | 122 | 1 | 80 | Jan 30 | ? | 1:31 | /usr/sbin/rpcbind |
| root | 124 | 1 | 80 | Feb 04 | ? | 0.37 | /usr/sbin/keyserv |
| gsmith | 1117 | 1115 | 80 | Feb 04 | pts/0 | 0:04 | -csh |
| ebrown | 1664 | 1662 | 80 | Feb 04 | pts/4 | 0:06 | -csh |
| ebrown | 2128 | 1664 | 80 | Feb 04 | pts/4 | 0:00 | /usr/bin/ps -ef |
- This ps output shows that the first process executed when the system boots is the swapper (sched) followed by the init process, pageout, and so on.
Looking for Problems
- Here are some tips on obvious problems you may find:
-
- Look for several identical jobs owned by the same user. This may come as a result of running a script that starts a lot of background jobs without waiting for any of the jobs to finish.
- Look for a process that has accumulated a large amount of CPU time. You'll see this by looking at the TIME field. Possibly, the process is in an endless loop.
- Look for a process running with a priority that is too high. Type ps -c to see the CLS field, which displays the scheduler class of each process. A process executing as a real-time (RT) process can monopolize the CPU. Or look for a timeshare (TS) process with a high nice value. A user with superuser privileges may have bumped up the priorities of this process. The system administrator can lower the priority by using the nice command.
- Look for a runaway process--one that progressively uses more and more CPU time. You can see it happening by looking at the time when the process started (STIME) and by watching the cumulation of CPU time (TIME) for awhile.

Process Priority Levels
- A process is allocated CPU time according to its scheduling class and its priority level. By default, the SunOS 5.x operating system has four process scheduling classes: real-time, system, timesharing and interactive.

-
- Real-time processes have the highest priority. This class includes processes that must respond to external events as they happen. For example, a process that collects data from a sensing device may need to process the data and respond immediately. In most cases, a real-time process requires a dedicated system. No other processes can be serviced while a real-time process has control of the CPU. By default, the range of priorities is 100-159.
- System processes have the middle priorities. This class is made up of those processes that are automatically run by the kernel, such as the swapper and the paging daemon. By default, the range of priorities is 60-99.
-
- Timesharing processes have the lowest priority. This class includes the standard UNIX processes. Normally, all user processes are timesharing processes. They are subject to a scheduling policy that attempts to distribute processing time fairly, giving interactive applications quick response time and maintaining good throughput for computations. By default, the range of priorities is 0-59.
- Interactive processes are introduced in the SunOS 5.4 environment. The priorities range from 0-59. All processes started under OpenWindows are placed in the interactive class and those processes with keyboard focus get higher priorities.
- The scheduling priority determines the order in which processes will be run.
- Real-time processes have fixed priorities. If a real-time process is ready to run, no system process or timesharing process can run.
- System processes have fixed priorities that are established by the kernel when they are started. The processes in the system class are controlled by the kernel, and cannot be changed.
- Timesharing and interactive processes are controlled by the scheduler, which dynamically assigns their priorities. You can manipulate the priorities of the processes within this class.
Changing the Scheduling Priority of Processes With priocntl

- The scheduling priority of a process is the priority it is assigned by the process scheduler. These priorities are assigned according to the scheduling policies of the scheduler. The dispadmin command lists the default scheduling policies. See Appendix B, "The Scheduler," for information on the dispadmin command.
- The priocntl command can be used to assign processes to a priority class and to manage process priorities. See the section called "Instructions for Managing Processes" on page 120 for instructions on using the priocntl command to manage processes.
Changing the Priority of a Timesharing Process With nice
- The nice command is only supported for backward compatibility to previous SunOS releases. The priocntl command provides more flexibility in managing processes.

- The priority of a process is determined by the policies of its scheduling class, and by its nice number. Each timesharing process has a global priority which is calculated by adding the user-supplied priority, which can be influenced by the nice or priocntl command, and the system-calculated priority.
- The execution priority number of a process is assigned by the operating system, and is determined by several factors, including its schedule class, how much CPU time it has used, and (in the case of a timesharing process) its nice number.
- Each timesharing process starts with a default nice number, which it inherits from its parent process. The nice number is shown in the NI column of the ps report.
- A user can lower the priority of a process by increasing its user-supplied priority. But only the system administrator (or root) can lower a nice number to increase the priority of a process. This is to prevent users from increasing the priorities of their own processes, thereby monopolizing a greater share of the CPU.
- Nice numbers range between 0 and +40, with 0 conferring the highest priority. The default value is 20. Two versions of the command are available, the standard version, /usr/bin/nice, and a version that is part of the C shell.
Killing a Process
- Sometimes it is necessary to stop (kill) a process. The process may be in an endless loop, or you may have started a large job that you want to stop before it is completed. You can kill any process that you own, and the superuser can kill any processes in the system except for those with PIDs 0, 1, 2, 3, and 4.
- You can destroy a process using the kill command:
-
-
kill PID
- The default action of this command is to send signal 15 to the process identified by the PID. You should use the ps command to be sure that the process is truly gone. If the process is still alive after the kill command, you can ensure its termination by sending the -9 signal:
-
-
kill -9 PID
-
Note - Some sleeping processes may be not wakeable by signals.
- You may find that although you have killed a process, the children have been inherited by init, and are still active. You can give multiple PIDs as arguments to the kill command.
Instructions for Managing Processes
- This section provides step-by-step instructions on how to control the processes starting up or being executed on your system.
· How to Get Basic Information About Process Classes
-
To display process class and scheduling parameters: * Type priocntl -l and press Return.

Example of Displaying Process Classes
- The listing below shows which classes are configured on your system, and the user priority range for the timesharing class. The possible classes are:
-
- System (SYS)
- Interactive (IA)
- Real-time (RT)
- Timesharing (TS)
· The user-supplied priority ranges from -20 to +20.
· The priority of a process is inherited from the parent process. This is referred to as the user-mode priority.
· The system looks up the user-mode priority in the timesharing dispatch parameter table and adds in any nice or priocntl (user-supplied) priority to and ensures a 0-59 range to create a global priority.
-
# priocntl -l
CONFIGURED CLASSES
==================
SYS (System Class)
TS (Time Sharing)
Configured TS User Priority Range: -20 through 20
#
|
-
To display the global priority of a process: * Type ps -ecl and press Return.
· How to Designate Priority With priocntl
-
To start a process with a designated priority: * Type priocntl -e -c class -m userlimit -p pri command_name and press Return.
-
- The -e option means execute the command.
- The -c option specifies the class within which to run the process. The default classes are TS or RT.
- The -m option is the maximum amount you can raise or lower your priority, when using -p option.
- For a real-time kernel thread, the -p option lets you specify the relative priority in the real RT class. For a timesharing process, the -p option lets you specify the user-supplied priority which ranges from-20 to +20.
Example of Using priocntl to Designate Priority
- The following example starts the find command running with the highest possible user-supplied priority:
-
% su root
# priocntl -e -c TS -m 20 -p 20 find . -name core -print
|
-
To change the scheduling parameters of a running timeshare process: * Type the following command:
-
priocntl -s -m userlimit [-p userpriority] -i idtype idlist
-
- The -s option lets you set the upper limit on the user priority range and change the current priority.
- The -m option is the maximum amount you can raise or lower your priority, when using -p option
- The -p option (optional) allows you to designate a priority.
- The -i option uses a combination of idtype and idlist to identify the process. The idtype specifies the type of ID, such as PID or UID.
Example of Changing the Scheduling Parameters of a Process
- The following example executes a command with a 500-millisecond time slice, a priority of 20 in the RT class, and a global priority of 120.
-
% su root
# priocntl -e -c RT -t 500 -p 20 myprog
|
· How to Change the Class of a Process
-
-
(Optional) Become superuser.
-
Note - You must be superuser or working in a real-time shell to change processes from, or to, real-time processes.
-
-
Type the following command:
-
-
priocntl -s -c class -i idtype idlist
- The -c option specifies the class, TS or RT, to which you are changing the process.
Example of Changing the Class of a Process
- The following example changes all the processes belonging to user 15249 to real-time processes:
-
% su
# priocntl -s -c RT -i uid 15249
|
-
Note - If, as superuser, you change a user process to the real-time class, the user cannot subsequently change the real-time scheduling parameters (using priocntl -s).
· How to Change the Priority of a Process with the nice Command
-
To lower the priority of a process: * Type one of the following commands:
-
-
/usr/bin/nice command_name
/usr/bin/nice +4 command_name
/usr/bin/nice -10 command_name
- These examples lower the priority of the command, command_name, by raising the nice number. The first two commands increase the nice number by four units (the default); and the second two commands increase the nice by ten units (the default), lowering the priority of the process.
-
To raise the priority of a process: * As root, type one of the following commands:
-
-
/usr/bin/nice -10 command_name
/usr/bin/nice - -10 command_name
- Both these examples raise the priority of the command, command_name, by lowering the nice number. Note that in the second case, the two minus signs are required. The first minus sign is the option sign, and the second minus sign indicates a negative number.
|
|