This chapter describes the procedures for managing system processes. This is a list of the step-by-step instructions in this chapter.
This section describes commands used to manage process information.
The ps command enables you to check the status of active processes on a system, as well as display technical information about the processes. This data is useful for such administrative tasks as determining how to set process priorities, and how to kill processes that have hung or become inactive.
Depending on which options you use, ps 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 63-1 describes some of the fields reported by the ps command. The fields displayed depend on which option you choose. See ps(1) for a description of all available options.
Table 63-1 Summary of Fields in ps Reports
Field |
Description |
---|---|
UID |
The effective user ID of the process's owner. |
PID |
The process ID. |
PPID |
The parent process's ID. |
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. |
ADDR |
The address of the proc structure. |
SZ |
The virtual address size of the 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. |
CMD |
The command that generated the process. |
To list all the processes being executed on a system, use the ps command.
$ ps [-ef] |
ps |
Displays only the processes associated with your login session. |
-ef |
Displays full information about all the processes being executed on the system. |
The following example shows output from the ps command when no options are used.
$ ps PID TTY TIME COMD 1664 pts/4 0:06 csh 2081 pts/4 0:00 ps |
The following example shows output from ps -ef. This shows that the first process executed when the system boots is sched (the swapper) followed by the init process, pageout, and so on.
$ ps -ef UID PID PPID C STIME TTY TIME CMD root 0 0 0 May 05 ? 0:04 sched root 1 0 0 May 05 ? 10:48 /etc/init - root 2 0 0 May 05 ? 0:00 pageout root 3 0 0 May 05 ? 43:21 fsflush root 238 1 0 May 05 ? 0:00 /usr/lib/saf/sac -t 300 root 115 1 0 May 05 ? 0:10 /usr/sbin/rpcbind root 158 1 0 May 05 ? 0:00 /usr/lib/autofs/autom... root 134 1 0 May 05 ? 0:12 /usr/sbin/inetd -s root 107 1 0 May 05 ? 11:49 /usr/sbin/in.routed -q root 117 1 5 May 05 ? 899:32 /usr/sbin/keyserv root 125 1 0 May 05 ? 0:00 /usr/sbin/kerbd root 123 1 0 May 05 ? 4:17 /usr/sbin/nis_cachemgr root 137 1 0 May 05 ? 0:00 /usr/lib/nfs/statd root 139 1 0 May 05 ? 0:02 /usr/lib/nfs/lockd root 159 1 50 May 05 ? 8243:36 /usr/sbin/automount root 199 191 0 May 05 ? 0:00 lpNet root 162 1 0 May 05 ? 0:07 /usr/sbin/syslogd root 181 1 0 May 05 ? 0:03 /usr/sbin/nscd... root 169 1 0 May 05 ? 5:09 /usr/sbin/cron root 191 1 0 May 05 ? 0:00 /usr/lib/lpsched root 210 1 0 May 05 ? 0:01 /usr/sbin/vold root 200 1 0 May 05 ? 0:08 /usr/lib/sendmail -bd -q1h root 4942 1 0 May 17 console 0:00 /usr/lib/saf/ttymon... root 208 1 0 May 05 ? 0:00 /usr/lib/utmpd root 241 238 0 May 05 ? 0:00 /usr/lib/saf/ttymon root 5748 134 0 17:09:49 ? 0:01 in.rlogind root 5750 5748 0 17:09:52 pts/0 0:00 -sh root 5770 5750 2 17:23:39 pts/0 0:00 ps -ef |
You can display detailed, technical information about active processes by using some of the process tool commands contained in /usr/proc/bin. Table 63-2 lists these process tools. Refer to proc(1)for more information.
Table 63-2 /usr/proc/bin Process Tools That Display Information
Process Tool |
What It Displays |
---|---|
pcred |
Credentials |
pfiles |
fstat and fcntl information for open files in a process |
pflags |
/proc tracing flags, pending and held signals, and other status information |
pldd |
Dynamic libraries linked into a process |
pmap |
Address space map |
psig |
Signal actions |
pstack |
Hex+symbolic stack trace |
ptime |
Process time using microstate accounting |
ptree |
Process trees that contain the process |
pwait |
Status information after a process terminates |
pwdx |
Current working directory for a process |
To avoid typing long command names, add the process tool directory to your PATH variable. This enables you to run process tools by entering only the last part of each file name (for example, pwdx instead of /usr/proc/bin/pwdx).
(Optional) Use output from the ps command to obtain the identification number of the process you want to display more information about.
# ps -e | grep process |
process |
Name of the process you want to display more information about. |
The process identification number is in the first column of the output.
Use the appropriate /usr/bin/proc command to display the information you need.
# /usr/proc/bin/pcommand pid |
pcommand |
Process tool command you want to run. Table 63-2 lists these commands. |
pid |
Identification number of a process. |
The following example shows how to use process tool commands to display more information about an lpsched process. First the /usr/proc/bin path is defined to avoid typing long process tool commands. Next, the identification number for lpsched is obtained. Finally, output from three process tool commands is shown.
The following example shows output from the pwait command, which waits until a process terminates, then displays information about what happened. The following example shows output from the pwait command after a Command Tool window was exited.
$ ps -e | grep cmdtool 273 console 0:01 cmdtool 277 console 0:01 cmdtool 281 console 0:01 cmdtool $ pwait -v 281 281: terminated, wait status 0x0000 |
You can control some aspects of processes by using some of the process tools contained in /usr/proc/bin. Table 63-3 lists these process tools. Refer to proc(1) for detailed information about process tools.
Table 63-3 /usr/proc/bin Process Tools That Provide Control
Process Tool |
What it Does |
---|---|
pstop |
Stops a process |
prun |
Restarts a process |
To avoid typing long command names, add the process tool directory to your PATH variable. This allows you to run process tools by entering only the last part of each file name (for example, prun instead of /usr/proc/bin/prun).
(Optional) Use output from the ps command to obtain the identification number of the process you want to display more information about.
# ps -e | grep process |
process |
Name of the process you want to display more information about. |
The process identification number is in the first column of the output.
Use the appropriate /usr/proc/bin command to control the process.
# /usr/proc/bin/pcommand PID |
pcommand |
Process tool command you want to run. Table 63-3 lists these commands. |
PID |
Identification number of a process. |
Verify the process status using the ps command.
# ps | grep PID |
The following example shows how to use process tools to stop and restart Print Tool.
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 superuser can kill any processes in the system except for those with process IDs 0, 1, 2, 3, and 4.
Refer to kill(1) for more detailed information.
(Optional) To kill a process belonging to another user, become superuser.
(Optional) Use output from the ps command to obtain the identification number of the process you want to display more information about.
$ ps -e | grep process |
process |
Name of the process you want to display more information about. |
The process identification number is in the first column of the output.
Use the kill command to stop the process.
$ kill [-9]PID ... |
-9 |
Ensures that the process terminates promptly. |
PID . . . |
ID of the process or processes to stop. |
Use the ps command to verify that the process has been stopped.
$ ps -ef | grep PID ... |
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)
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 and ensures a 0-59 range to create a global priority.
The scheduling priority of a process is the priority it is assigned by the process scheduler, according to scheduling policies. The dispadmin command lists the default scheduling policies. See "Scheduler Configuration", 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 "How to Designate a Process Priority" for instructions on using the priocntl command to manage processes.
You can display process class and scheduling parameters with the priocntl -l command.
$ priocntl -l |
The following example shows output from the priocntl -l command.
$ priocntl -l CONFIGURED CLASSES ================== SYS (System Class) TS (Time Sharing) Configured TS User Priority Range: -20 through 20 |
You can display the global priority of a process by using the ps command.
$ ps -ecl |
The global priority is listed under the PRI column.
The following example shows output from ps -ecl. Data in the PRI column show that pageout has the highest priority, while sh has the lowest.
$ ps -ecl F S UID PID PPID CLS PRI ADDR SZ WCHAN TTY TIME COMD 19 T 0 0 0 SYS 96 f00d05a8 0 ? 0:03 sched 8 S 0 1 0 TS 50 ff0f4678 185 ff0f4848 ? 36:51 init 19 S 0 2 0 SYS 98 ff0f4018 0 f00c645c ? 0:01 pageout 19 S 0 3 0 SYS 60 ff0f5998 0 f00d0c68 ? 241:01 fsflush 8 S 0 269 1 TS 58 ff0f5338 303 ff49837e ? 0:07 sac 8 S 0 204 1 TS 43 ff2f6008 50 ff2f606e console 0:02 sh |
Start a process with a designated priority.
# priocntl -e -c class-muserlimit-p pri command_name |
-e |
Executes the command. |
-c class |
Specifies the class within which to run the process. The default classes are TS (timesharing) or RT (real-time). |
-m userlimit |
Specifies the maximum amount you can raise or lower your priority, when using the -p option. |
-p pri command_name |
Lets you specify the relative priority in the RT class, for a real-time thread. For a timesharing process, the -p option lets you specify the user-supplied priority which ranges from -20 to +20. |
Verify the process status by using the ps -ecl command.
# ps -ecl | grep command_name |
The following example starts the find command with the highest possible user-supplied priority.
# priocntl -e -c TS -m 20 -p 20 find . -name core -print # ps -ecl | grep find |
Change the scheduling parameter of a running timeshare process.
# priocntl -s -m userlimit [-p userpriority] -i idtype idlist |
-s |
Lets you set the upper limit on the user priority range and change the current priority. |
-m userlimit |
Specifies the maximum amount you can raise or lower your priority, when using the -p option. |
-p userpriority |
Allows you to designate a priority. |
-i idtype idlist |
Uses a combination of idtype and idlist to identify the process. The idtype specifies the type of ID, such as PID or UID. |
Verify the process status by using the ps --ecl command.
# ps -ecl | grep idlist |
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.
# priocntl -e -c RT -t 500 -p 20 myprog # ps -ecl | grep myprog |
You must be superuser or working in a real-time shell to change processes from, or to, real-time processes.
Change the class of a process.
# priocntl -s -c class -i idtype idlist |
-s |
Lets you set the upper limit on the user priority range and change the current priority. |
-c class |
Specifies the class, TS or RT, to which you are changing the process. |
-i idtype idlist |
Uses a combination of idtype and idlist to identify the process. The idtype specifies the type of ID, such as PID or UID. |
Verify the process status by using the ps -ecl command.
# ps -ecl | grep idlist |
The following example changes all the processes belonging to user 15249 to real-time processes.
# priocntl -s -c RT -i uid 15249 # ps -ecl | grep 15249 |
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).
The nice command is only supported for backward compatibility to previous Solaris 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 commands, 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 superuser 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 representing 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.
You can raise or lower the priority of a command or a process by changing the nice number. To lower the priority of a process:
/usr/bin/nice command_name |
Increase the nice number by four units (the default) |
/usr/bin/nice +4 command_name |
Increase the nice number by four units |
/usr/bin/nice -10 command_name |
Increase the nice number by ten units |
The first and second commands increase the nice number by four units (the default); and the third command increases the nice by ten units, lowering the priority of the process.
The following commands raise the priority of the command by lowering the nice number.
To raise the priority of a process:
/usr/bin/nice -10 command_name |
Raises the priority of the command by lowering the nice number |
/usr/bin/nice - -10 command_name |
Raises the priority of the command by lowering the nice number. The first minus sign is the option sign, and the second minus sign indicates a negative number. |
The above commands 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.
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.