[ Team LiB ] Previous Section Next Section

Monitoring Processes

The programs that are running on a system at any one time are called processes. You can monitor the status of processes, control how much CPU time a process gets, find or signal processes, and suspend or halt the execution of a process.

Commands for Monitoring Processes

The ps (process status) command is your main tool for obtaining information about processes. You can use the ps command in combination with the grep command to focus your search for specific information.

You can also use the dispadmin, priocntl, nice, renice, pgrep, and pkill commands to manage processes. Table 9 lists the commands for managing processes.

Table 9. Commands for Managing Processes

Command

Description

ps

Check the status of active processes on a system and display detailed information about the processes.

dispadmin

List default scheduling policies.

priocntl

Assign processes to a priority class and manage process priorities.

nice

Raise or lower the priority of a timesharing process.

renice

Alter the scheduling priority of one or more running processes.

pgrep, pkill

Find or signal processes.

Refer to the ps(1), dispadmin(1M), priocntl(1), nice(1), renice(1), pgrep(1), and pkill(1) manual pages for complete information about these commands.

In addition, the /usr/proc/bin directory contains process tools that you can use to display highly detailed information about the processes listed in /proc. The /proc directory is also known as the process file system (procfs). ProcFS maps process information into the file system, enabling you to manipulate process attributes with a file-access paradigm. For more information about the /proc file system, see "Types of File Systems" on page 182.

The process tools are similar to some options of the ps command, except that the output provided by the tools is more detailed. In general, the process tools do the following.

  • Display more details about processes, such as fstat and fcntl information, working directories, and trees of parent and child processes.

  • Provide control over processes, enabling users to stop or resume them.

Table 10 summarizes the /usr/proc/bin commands.

Table 10. Process Tools in the /usr/proc/bin Directory

Command

Description

pcred pid

Display credentials.

pfiles pid

Display fstat and fcntl information for open files.

graphics/new.gif pargs

Print the command arguments (argv[]), environment variables, or auxiliary vector. New in the Solaris 9 release.

pflags pid

Show /proc tracing flags, pending and held signals, and other status information for each LWP.

pldd pid

Show dynamic libraries linked into each process.

pmap pid

Show address map space.

prun pid

Restart the process.

psig pid

Display signal actions.

pstack pid

Display hex+symbolic stack trace for each LWP.

pstop pid

Stop the process.

ptime pid

Time the process, using microstate accounting.

ptree pid

Show process trees containing specified PIDs.

pwait pid

Wait for the specified processes to terminate.

pwdx pid

Display current working directory.

graphics/new.gif

Starting with the Solaris 8 release, some of the proc tools can also be applied to corefiles. A corefile is a snapshot of a process's state and is produced by the kernel before terminating a process with a signal or with the gcore(1) command. Some of the proc tools may need to derive the name of the executable corresponding to the process that dumped core or the names of shared libraries associated with the process. These files are needed, for example, to provide symbol table information for pstack(1). If the proc tool in question is unable to locate the needed executable or shared library, some symbol information is unavailable for display. Similarly, if a corefile from one operating system release is examined on a different operating system release, the runtime link-editor debugging interface (librtld_db) may not be able to initialize. In this case, symbol information for shared libraries is not available.

For a complete description of the process tools, refer to the proc(1) manual page. For information about how to use the process tools commands to display details about processes and how to start and stop them, see "Using the /usr/proc/bin Commands" on page 55.

Using the ps Command

You can use the ps command to determine which processes are running (or not running) and to get the following detailed information about an individual process.

  • PID (process ID).

  • UID (user ID).

  • Priority.

  • Control terminal.

  • Memory use.

  • CPU time.

  • Current status.

The ps command takes a snapshot of system activity at the time you type the command. If you are monitoring system activity by time, be aware that the results are already slightly out-of-date by the time you read them. Table 11 shows the most frequently used options for the ps command. See the ps(1) manual page for a complete list of options.

Table 11. Most Frequently Used Options for the ps Command

Option

Description

–e

Report on all processes.

–f

Show the owner of the process, by name instead of by UID, in the first column. This option turns off –1, –t, –s, and –r and turns on –a.

–l

Generate a long report, which includes all fields except STIME.

What the ps Command Reports

When you type ps -e and press Return, you get a report that looks like the following example.

graphics/new.gif

mopoke% ps -e
   PID TTY     TIME CMD
     0 ?       0:16 sched
     1 ?       0:00 init
     2 ?       0:00 pageout
     3 ?       0:00 fsflush
   411 ?       0:00 sac
   237 ?       0:00 utmpd
   208 ?       0:00 nscd
    49 ?       0:00 sysevent
    56 ?       0:00 picld
   115 ?       0:00 in.route
   179 ?       0:00 automoun
   133 ?       0:00 rpcbind
   189 ?       0:00 syslogd
   155 ?       0:00 inetd
   213 ?       0:00 lpsched
   170 ?       0:00 lockd
   176 ?       0:00 statd
   511 ?       0:00 dtfile
   193 ?       0:00 cron
   226 ?       0:00 powerd
   440 ?       0:00 Xsession
   414 ?       0:00 ttymon
   261 ?       0:02 vold
   249 ?       0:00 smcboot
   248 ?       0:00 smcboot
   250 ?       0:00 smcboot
   266 ?       0:00 htt
   268 ?       0:00 htt_serv
   401 ?       0:00 dmispd
   372 ?       0:00 auditd
   283 ?       0:00 dwhttpd
   284 ?       0:23 dwhttpd
   416 ?       0:00 sshd
   434 ?       0:00 sendmail
   454 ?       0:00 speckeys
   432 ?       0:00 sendmail
   439 ?       0:00 dtlogin
   450 ?       0:00 fbconsol
   487 pts/3   0:00 csh
   503 pts/3   0:00 dtsessio
   484 pts/3   0:00 sdt_shel
   485 ?       0:00 dsdm
   584 pts/6   0:00 ftp
   419 ?       0:00 mibiisa
   418 ??      0:00 fbconsol
   402 ?       0:00 snmpXdmi
   415 ?       0:04 Xsun
   395 ?       0:00 dtlogin
   392 ?       0:00 snmpdx
   412 console 0:00 ttymon
   417 ?       0:00 dtlogin
   504 ?       0:00 rpc.ttdb
   502 pts/3   0:00 ttsessio
   510 ?       0:01 dtwm
   537 ?       0:00 rpc.rsta
   513 ??      0:01 dtterm
   514 ?       0:00 sdtperfm
   515 pts/3   0:00 sh
   516 pts/3   0:00 dtpad
   548 ?       0:00 cat
   518 ?       0:00 sdtvolch
   535 pts/7   0:00 csh
   522 pts/4   0:00 csh
   525 pts/5   0:00 csh
   529 pts/6   0:00 csh
   638 pts/4   0:00 ps
   569 ?       0:04 .netscape
   568 ?       0:00 netscape
   570 ?       0:00 netscape
   571 ?       0:00 .netscape
mopoke%

The columns are described in Table 12.

Table 12. Columns in the ps -e Report

Column

Description

PID

Process identification number.

TTY

The terminal from which the process (or its parent) started. If the process has no controlling terminal, this column contains a question mark (?). Processes with question marks usually are system processes.

TIME

The cumulative amount of CPU time used by the process.

CMD

The name of the command that generated the process. Note that for the ps -e command only the first eight characters of the file name are displayed.

When you type ps -el and press Return, you get a listing that looks like the following example.

graphics/new.gif

mopoke% ps -el
 F S   UID   PID  PPID  C  PRI  NI    ADDR      SZ       WCHAN  TTY          TIME CMD
19 T     0     0     0  0    0  SY       ?       0              ?            0:16 sched
 8 S     0     1     0  0   40  20       ?     150           ?  ?            0:00 init
19 S     0     2     0  0    0  SY       ?       0           ?  ?            0:00 pageout
19 S     0     3     0  0    0  SY       ?       0           ?  ?            0:00 fsflush
 8 S     0   411     1  0   40  20       ?     216           ?  ?            0:00 sac
 8 S     0   237     1  0   40  20       ?     130           ?  ?            0:00 utmpd
 8 S     0   208     1  0   40  20       ?     349           ?  ?            0:00 nscd
 8 S     0    49     1  0   40  20       ?     268           ?  ?            0:00 sysevent
 8 S     0    56     1  0   40  20       ?     367           ?  ?            0:00 picld
 8 S     0   115     1  0   40  20       ?     207           ?  ?            0:00 in.route
 8 S     0   179     1  0   40  20       ?     475           ?  ?            0:00 automoun
 8 S     0   133     1  0   40  20       ?     272           ?  ?            0:00 rpcbind
 8 S     0   189     1  0   40  20       ?     414           ?  ?            0:00 syslogd
 8 S     0   155     1  0   40  20       ?     297           ?  ?            0:00 inetd
 8 S     0   213     1  0   40  20       ?     391           ?  ?            0:00 lpsched
 8 S     0   170     1  0   40  20       ?     266           ?  ?            0:00 lockd
 8 S     1   176     1  0   40  20       ?     306           ?  ?            0:00 statd
 8 S  1001   511   503  0   50  20       ?    1097           ?  ?            0:00 dtfile
 8 S     0   193     1  0   40  20       ?     253           ?  ?            0:00 cron
 8 S     0   226     1  0   40  20       ?     174           ?  ?            0:00 powerd
 8 S  1001   440   439  0   40  20       ?     240           ?  ?            0:00 Xsession
 8 S     0   414   411  0   40  20       ?     217           ?  ?            0:00 ttymon
 8 S     0   261     1  0   40  20       ?     363           ?  ?            0:02 vold
 8 S     0   249   248  0   40  20       ?     215           ?  ?            0:00 smcboot
(Additional lines deleted from this example)

Table 13 describes the fields in the long listing report.

graphics/new.gif

NOTE. The ADDR field is obsolete and contains only question marks.


Table 13. Summary of Fields in a ps -el Report

Field

Description

graphics/new.gifF

Hexadecimal flags, which, added together, indicate the process's current state. These flags are available for historical purposes. You should ascribe no meaning to them.

 

00

The process has terminated. Its place in the process table is free.

 

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 being traced by its parent and has been stopped.

 

08

The process cannot be awakened by a signal.

 

10

The process is currently in memory and is locked until an event completes.

 

20

The process cannot be swapped.

S

The current state of the process, as shown by one of the following letters.

 

O

Currently running on the processor.

 

S

Sleeping; waiting for an I/O event to complete.

 

R

Ready to run.

 

I

Idle; process is being created.

 

Z

Zombie. The process has terminated and the parent is not waiting, but the dead process is still in the process table.

 

T

Stopped because the parent is tracing the process.

 

X

Waiting for more memory.

UID

The user ID of the owner of the process.

PID

The process identification number.

PPID

The parent process's identification number.

C

The process's CPU use (that is, an estimate of the percentage of CPU time used by the process).

PRI

The process's scheduling priority. Higher numbers mean lower priority.

NI

The process's nice number, which contributes to its scheduling priority. Making a process "nicer" means lowering its priority so it does not use up as much CPU time.

graphics/new.gifADDR

The memory size of the process. Note that the ADDR field is obsolete and is not displayed with some options.

SZ

The amount of virtual memory required by the process. This is a good indication of the demand the process puts on system memory.

graphics/new.gifWCHAN

The address of an event for which the process is sleeping. When this field is blank, the process is running.

TTY

The terminal from which the process (or its parent) started, or a question mark to indicate there is no controlling terminal (which usually indicates a system process).

TIME

The total amount of CPU time used by the process since it began.

COMD

The command being run by the process.

Uses for the ps Report

When you need to check on which processes or daemons are running, use the ps -e option. If you need more detailed information about a process, use the ps -el options. See the ps(1) manual page for a complete list of options. With experience, you will know how the report should look and be able to judge what is out of the ordinary.

The following guidelines can help you spot potential problems.

  • Look for many identical jobs owned by the same user. This condition may result from someone running a script that starts a lot of background jobs without waiting for any of the jobs to terminate. Talk to the user to find out if that's the case. If necessary, use the kill command to terminate some of the processes. See "Killing Processes" on page 53 for more information on killing a process.

  • Look at the TIME field for processes that have accumulated a large amount of CPU time. Such processes might be in an endless loop.

  • Look at the C field to find unimportant processes that consume a large percentage of CPU time. If you do not think a process warrants so much attention, use the priocntl command to lower its priority. See the priocntl(1M) manual page for more information.

  • Look at the SZ field for processes that consume too large a percentage of memory. If a process is a memory hog, you may need to kill the process. If many processes are using lots of memory, the system may need more memory.

  • Watch for a runaway process that uses progressively more CPU time. You can check this by using the -f option to see the start time (STIME) of the process and by watching the TIME field for the accumulation of CPU time.

Signalling a Process

graphics/new.gif

The Solaris Operating Environment provides a way to signal processes. A signal is an asynchronous notification of an event. With signals, you can interrupt a process or a thread within a process as the result of a specific event. Asynchronous signals can result from the current instruction stream. Such signals originate as hardware trap conditions for conditions such as illegal address references (segmentation violation) and illegal math operations (floating-point exceptions).

The system also implements asynchronous signals that result from an external event that may not be related to the current instruction stream. Examples of such signals are job control signals, one process or thread sending a signal to another, or a kill signal sent to terminate a process.

For example, the SIGHUP signal hangs up a process, SIGINT interrupts a process, and SIGKILL kills a process. Refer to signal(3HEAD) for a complete list of signals.

Most signals can be ignored, a signal can be caught and a process-specific signal handler invoked, or a process can permit the default action to be taken. Every signal has a predefined default action.

Killing Processes

You can use the kill command to deliver different signal types to programs. Many of those signals instruct a program to perform some predetermined and normal action. The following section describes how to use the kill command to terminate a process.

You can use the kill command to eliminate a process entirely. The syntax of the kill command is kill -signal PID, where signal is a number or a name and PID is the process ID of the process to which you send the signal.

The usual way to kill a process is to send it a certain signal. The TERM (-15) signal generally cleanly shuts down a process. If TERM (or some other signal you know the process is prepared to accept and act on) doesn't work, then you can send the KILL (-9) signal as a last resort. The KILL (-9) signal may result in loss of data, so you should not use it indiscriminately.

Sometimes processes do not die when you use the kill command. The three most common cases are listed below.

  • The process is waiting for a device, such as a tape drive, to complete an operation before exiting.

  • The process is waiting for resources that are unavailable because of NFS problems. To kill such a process, type kill -QUIT PID.

  • graphics/new.gif The process is a zombie, as shown by the message defunct in the ps report. A zombie process is one that has had all its resources freed but has not received an acknowledgment from a parent process, receipt of which would ordinarily remove its entry from the process table. The next time a system is booted, zombie processes are cleared. The Solaris 9 Operating Environment provides the preap(1) command that you can use to force a defunct process to be reaped by its parent.

Use the following steps to kill a process.

  1. Become superuser.

    You must be superuser to kill a process that you do not own.

  2. Type ps -e and press Return.

    A list of the processes is displayed. Use the PID (process ID) number in the first column as input to the next step. If you know which process is causing the problem, you can type ps -e | grep process-name and press Return to focus your search.

  3. Type kill PID and press Return.

    When you type kill with no signal argument, signal 15 is sent.

  4. Type ps -e and press Return.

    Check to see if the process has terminated. If it's still there, go to step 5.

  5. Type kill -9 PID and press Return.

    The process should be terminated. To see a description of the signals used by kill, type man -s5 signal and press Return.

In the following example, OpenWindows is frozen on the system oak. You must log in remotely from another system and kill the process.


elm% rlogin oak
Password:
oak% ps -e | grep openwin
PID TTY      TIME COMD
2212 pts/0 0:00 openwin
2213 pts/1 0:00 grep openwin
oak% su
Password:
oak# kill 2212
oak# exit
oak% logout
elm%



Using the /usr/proc/bin Commands

Starting with the Solaris 2.6 release, you can use a set of commands to display detailed, technical information about active processes. These commands are summarized in Table 14.

Table 14. Process Tools in the /usr/proc/bin Directory

Command

Description

pcred pid[*]

Display credentials.

pfiles pid[*]

Display fstat and fcntl information for open files.

pflags pid[*]

Show /proc tracing flags, pending and held signals, and other status information for each LWP.

pldd pid[*]

Show dynamic libraries linked into each process.

pmap pid[*]

Show address map space.

prun pid

Restart the process.

psig pid[*]

Display signal actions.

pstack pid[*]

Display hex+symbolic stack trace for each LWP.

pstop pid

Stop the process.

ptime pid

Time the process, using microstate accounting.

ptree pid

Show process trees containing specified PIDs.

pwait pid

Wait for specified processes to terminate.

pwdx pid[*]

Display current working directory.

[*] Must be superuser to execute

NOTE. If you use the /usr/proc/bin commands frequently, add the process tool directory to your PATH variable to make the commands more easily accessible.


All of the /usr/bin/proc commands use the process ID (PID) as the argument to the command. You can obtain the PID by using the ps -e and the grep commands to search for the name of the process you want more information about. The following example displays the PID for the openwin process in the first column.


oak% ps -e | grep openwin
PID TTY         TIME COMD
2212 pts/0      0:00 openwin
2213 pts/1       0:00 grep openwin
oak%


Displaying and Controlling Information About Processes

Use the following steps to display and control information about a process.

  1. Type ps -e | grep process-name and press Return. The first column of the output displays the PID for the appropriate process name.

  2. Become superuser to use pcred, pfiles, pflags, pldd, pmap, psig, pstack, and pwdx commands.

  3. Type command PID and press Return.

    The information for the specified command is displayed.

The following examples show the output for each of the /usr/proc/bin commands for the dtlogin PID of 283.


castle% ps -e | grep dtlogin
   283 ?        0:00 dtlogin
   270 ?        0:01 dtlogin
castle%
# /usr/proc/bin/pcred 283
283: e/r/suid=0 e/r/sgid=0
     groups: 1 0 2 3 4 5 6 7 8 9 12
# exit
castle% /usr/proc/bin/ptime 283

real       0.016
user       0.000
sys        0.016
castle%
# /usr/proc/bin/pfiles 283
283:        /usr/dt/bin/dtlogin -daemon
  Current rlimit: 64 file descriptors
   0: S_IFDIR mode:0755 dev:32,24 ino:2 uid:0 gid:0 size:1024
      O_RDONLY|O_LARGEFILE
   1: S_IFDIR mode:0755 dev:32,24 ino:2 uid:0 gid:0 size:1024
      O_RDONLY|O_LARGEFILE
   2: S_IFREG mode:0644 dev:32,24 ino:326220 uid:0 gid:0 size:49
      O_WRONLY|O_APPEND|O_LARGEFILE
   3: S_IFCHR mode:0666 dev:32,24 ino:406038 uid:0 gid:3 rdev:13,12
      O_RDWR
   4: S_IFIFO mode:0666 dev:171,0 ino:4124779288 uid:0 gid:0 size:0
      O_RDWR|O_NONBLOCK
   5: S_IFREG mode:0644 dev:32,24 ino:326221 uid:0 gid:0 size:4
      O_WRONLY|O_LARGEFILE
      advisory write lock set by process 270
   7: S_IFSOCK mode:0666 dev:166,0 ino:32032 uid:0 gid:0 size:0
      O_RDWR
   8: S_IFDOOR mode:0444 dev:171,0 ino:4124780632 uid:0 gid:0 size:0
      O_RDONLY|O_LARGEFILE FD_CLOEXEC door to nscd[174]
#
# /usr/proc/bin/pflags 283
283:    /usr/dt/bin/dtlogin -daemon
  /1:   flags = PR_PCINVAL|PR_ORPHAN|PR_ASLEEP [ wait() ]
#
# /usr/proc/bin/pldd 283
283:    /usr/dt/bin/dtlogin -daemon
/usr/openwin/lib/libXmu.so.4
/usr/openwin/lib/libX11.so.4
/usr/dt/lib/libDtSvc.so.1
/usr/lib/libresolv.so.2
/usr/lib/libdl.so.1
/usr/lib/libbsm.so.1
/usr/lib/libauth.so.1
/usr/lib/libsocket.so.1
/usr/lib/libnsl.so.1
/usr/dt/lib/libSDtFwa.so.1
/usr/lib/libc.so.1
/usr/openwin/lib/libXt.so.4
/usr/openwin/lib/libSM.so.6
/usr/openwin/lib/libICE.so.6
/usr/openwin/lib/libXext.so.0
/usr/lib/libm.so.1
/usr/openwin/lib/libtt.so.2
/usr/dt/lib/libXm.so.3
/usr/lib/libmp.so.2
/usr/lib/nss_files.so.1
/usr/lib/libpam.so.1
#
# /usr/proc/bin/pmap 283
283:    /usr/dt/bin/dtlogin -daemon
00010000       108K read/exec           /usr/dt/bin/dtlogin
0003A000        32K read/write/exec     /usr/dt/bin/dtlogin
00042000        80K read/write/exec       [ heap ]
EEE90000        12K read/shared         dev:32,24 ino:196384
EEEA0000        12K read/shared         dev:32,24 ino:196384
EEEB0000        12K read/shared         dev:32,24 ino:196384
EEEC0000         8K read/write            [ anon ]
EEF11000         4K read/write            [ anon ]
EEF89000         4K read/write            [ anon ]
EF001000         4K read/write            [ anon ]
EF060000        24K read/exec           /usr/lib/libpam.so.1
EF075000         4K read/write/exec     /usr/lib/libpam.so.1
(More information, not shown here)
EF7C0000         4K read/exec/shared    /usr/lib/libdl.so.1
EF7D0000       112K read/exec           /usr/lib/ld.so.1
EF7FB000         8K read/write/exec     /usr/lib/ld.so.1
EF7FD000         4K read/write/exec       [ anon ]
EFFF9000        28K read/write/exec       [ stack ]
 total        5480K
#
# /usr/proc/bin/psig 283
283:    /usr/dt/bin/dtlogin -daemon
HUP        ignored
INT        caught RESETHAND,NODEFER
QUIT       ignored
ILL        default
TRAP       default
ABRT       default
EMT        default
FPE        default
KILL       default
BUS        default
SEGV       default
SYS        default
PIPE       ignored
ALRM       default
TERM       caught RESETHAND,NODEFER
USR1       caught RESETHAND,NODEFER
USR2       default
CLD        default NOCLDSTOP

PWR        default
WINCH      default
URG        default
POLL       default
STOP       default
TSTP       default
CONT       default
TTIN       ignored
TTOU       default
VTALRM     default
PROF       default
XCPU       ignored
XFSZ       ignored
WAITING    default
LWP        default
FREEZE     default
THAW       default
CANCEL     default
LOST       default
RTMIN      default
RTMIN+1    default
RTMIN+2    default
RTMIN+3    default
RTMAX-3    default
RTMAX-2    default
RTMAX-1    default
RTMAX      default
#
# /usr/proc/bin/pstack 283
283:    /usr/dt/bin/dtlogin -daemon
 ef479154 wait ()
 ef479154 _libc_wait (0, 3ec4c, 3b000, 12d, ef4e227c, 1e340) + 8
 0001e340 ManageSession (43000, 43000, 482f8, ef001230, 81010100, c) + 454
 00019348 StartDisplay (482f8, 3c954, 43000, 3b224, ef001240, ff00) + 7bc
 0001a324 ForEachDisplay (189a8, 0, 2400, 41800, 42e48, 17ca8) + 1c
 00017d54 main (0, effffefc, efffff08, 3b000, 0, 0) + 228
 0001541c _start (0, 0, 0, 0, 0, 0) + dc
#
# /usr/proc/bin/pwdx 283
283:           /
#
castle% /usr/proc/ptime 283

real            0.066
user            0.000
sys             0.032
castle%
castle% ptree 283
270 /usr/dt/bin/dtlogin -daemon
  283 /usr/dt/bin/dtlogin -daemon
    301 /bin/ksh /usr/dt/bin/Xsession
      311 /usr/openwin/bin/fbconsole
      346 /usr/dt/bin/sdt_shell -c unsetenv _ PWD;                    unsetenv DT;
          349 -csh -c unsetenv _ PWD;             unsetenv DT;             setenv
  DISP
            366 /usr/dt/bin/dtsession
              373 dtwm
                374 dtterm -session dt0vPI0t -sdtserver
                  387 /bin/csh
                    407 ./textedit
                    528 sh
                  390 /bin/csh
                  393 /bin/csh
                    417 /usr/openwin/bin/cmdtool
                      420 /bin/csh
                 531 /bin/csh
                   553 ptree 283
               375 dtfile -session dtbfiQD_
                 405 dtfile -session dtbfiQD_
               376 snapshot -Wp 781 588 -Ws 326 201 -WP 6 6 +Wi -f snapshot.rs
castle%




The Priority Control Command (priocntl)

You can use the priocntl command to display or set scheduling parameters of specified processes. You can also use it to display the current configuration information for the process scheduler of a system or to execute a command with specified scheduling parameters.

Solaris provides several scheduling classes, each with its own scheduling policy. A process can be assigned to one of these classes; the process priority can then be adjusted within the boundaries allowed by that particular scheduling class.

  • System (SYS).

    Use the system scheduling class to schedule the execution of certain special system processes such as the swapper process.

  • Interactive (IA).

    Use the interactive class to provide good response time to interactive processes and good throughput to CPU-bound jobs. This class gives snappier performance than does SYS for GUI programs such as X11, CDE, and OpenWindows that the user interacts with. You can change the processes of the interactive class in the same way as those in the timesharing class, although the modified priorities continue to be adjusted to provide good responsiveness for user interaction.

  • Real-time (RT).

    Use the real-time class to provide a fixed-priority, preemptive scheduling policy for those processes that need fast responses and absolute user and application control of scheduling priorities.

  • Timesharing (TS).

    Use the timesharing class to provide fair and effective allocation of CPU resources among processes that have varying CPU consumption requirements.

  • graphics/new.gif Fair-share (FS), new in the Solaris 9 release.

    Use the fair-share class to provide a fair allocation of system CPU resources among projects independently of the number of processes they own. Processes are given "shares" to control their entitlement to CPU resources.

  • graphics/new.gif Fixed-priority (FX), new in the Solaris 9 release.

    Use the fixed-priority class to provide a fixed-priority, preemptive-scheduling policy for those processes that cannot handle dynamic adjustments and require that the user or application have control of the scheduling priorities. The fixed-priority class values range from 0–60.

For the timesharing class, the user-supplied priority ranges from –20 to +20. The priority of a timeshare process, referred to as the user-mode priority, is inherited from the parent process. The system looks up the user-mode priority in its timesharing dispatch parameter table, adds in any nice or priocntl (user-supplied) priority, and ensures a 0–59 range to create a global priority.

In the default configuration, a runnable real-time process runs before any other process. Inappropriate use of real-time processes can have a dramatic, negative impact on system performance.

Creating and Administering Resource Management Pools

graphics/new.gif

Starting with the Solaris 9 release, you can create permanent processor sets, called resource pools, and associate a scheduling class with that set. You can then assign projects to that resource pool. Use the poolcfg(1M) command to create XML-based pool configuration files. The systemwide configuration is stored in /etc/pooladm.conf.

Once you have created a pool configuration file, activate it with the pooladm(1M) command, which is also automatically run at boot time if the /etc/pooladm.conf file is present. You can bind processes, tasks, or projects to a pool with the poolbind(1M) command or query the binding for a process, if you have the appropriate authorizations. You can also specify the binding of a project to a pool with an attribute in the project(4) database. This binding is used when you are logging in or when you use the newtask(1) command.

Solaris 9 also introduces the concept of a task, which is a collection of processes. Tasks remove the limitations of current process aggregates such as process groups and sessions. Tasks are bound to projects whose membership and attributes are described in the project(4) database. The SMC Projects tool is a GUI front end that you can use to administer projects and tasks in addition to the commands. Refer to Sun's System Administration Guide: Resource Management and Network Services and the relevant manual pages for more information about creating and administering resource management pools.

Displaying Basic Information About Process Classes

Use the following procedure to display basic information about process classes.

  • Type priocntl -l and press Return. The process class and scheduling parameters for the system are displayed.

In the following example, all classes except RT are loaded at the moment.


paperbark% priocntl -l
CONFIGURED CLASSES
==================

SYS (System Class)

TS (Time Sharing)
        Configured TS User Priority Range: -60 through 60

IA (Interactive)
        Configured IA User Priority Range: -60 through 60
paperbark%



Displaying the Global Priority of a Process

You can use the ps command to display the global priority of a process. The global priority is listed under the PRI column.

graphics/new.gif

With the -c option to ps, higher numbers in the PRI column mean higher priority. Without the -c option, higher numbers mean lower priority.

graphics/new.gif

The following example shows the output from the ps -ecl command. Data in the PRI column shows that pageout has the highest priority at 98, and the dtfile, dtpad, and dtsession commands have the lowest at 49.

graphics/new.gif

mopoke% ps -ecl
 F S  UID   PID  PPID CLS PRI   ADDR   SZ   WCHAN TTY      TIME CMD
19 T    0     0     0 SYS  96      ?    0         ?        0:13 sched
 8 S    0     1     0  TS  59      ?  150       ? ?        0:00 init
19 S    0     2     0 SYS  98      ?    0       ? ?        0:00 pageout
19 S    0     3     0 SYS  60      ?    0       ? ?        0:00 fsflush
 8 S    0   411     1  TS  59      ?  216       ? ?        0:00 sac
 8 S    0   237     1  TS  59      ?  130       ? ?        0:00 utmpd
 8 S    0   208     1  TS  59      ?  347       ? ?        0:00 nscd
 8 S    0    49     1  TS  59      ?  268       ? ?        0:00 sysevent
 8 S    0    56     1  TS  59      ?  367       ? ?        0:00 picld
 8 S    0   115     1  TS  59      ?  207       ? ?        0:00 in.route
 8 S    0   179     1  TS  59      ?  475       ? ?        0:00 automoun
 8 S    0   133     1  TS  59      ?  272       ? ?        0:00 rpcbind
 8 S    0   170     1  TS  59      ?  266       ? ?        0:00 lockd
 8 S    0   155     1  TS  59      ?  297       ? ?        0:00 inetd
 8 S    0   189     1  TS  59      ?  414       ? ?        0:00 syslogd
 8 S    0   213     1  TS  59      ?  391       ? ?        0:00 lpsched
 8 S    1   176     1  TS  59      ?  306       ? ?        0:00 statd
 8 S    0   193     1  TS  59      ?  253       ? ?        0:00 cron
 8 S    0   226     1  TS  59      ?  174       ? ?        0:00 powerd
 8 S    0   414   411  TS  59      ?  217       ? ?        0:00 ttymon
 8 S    0   261     1  TS  59      ?  363       ? ?        0:02 vold
 8 S    0   249   248  TS  59      ?  215       ? ?        0:00 smcboot
 8 S    0   248     1  TS  59      ?  215       ? ?        0:00 smcboot
 8 S    0   250   248  TS  59      ?  215       ? ?        0:00 smcboot
 8 S    0   266     1  TS  59      ?  121       ? ?        0:00 htt
 8 S    0   268   266  TS  59      ?  378       ? ?        0:00 htt_serv
 8 S 1001   416   395  IA  59      ? 3568       ? ?        0:07 Xsun
 8 S    0   372     1  TS  59      ?  227       ? ?        0:00 auditd
 8 S    1   283     1  TS  59      ? 1178       ? ?        0:00 dwhttpd
 8 S    1   284   283  TS  59      ? 1277       ? ?        0:00 dwhttpd
 8 S    0   417   395  IA  59      ?  662       ? ?        0:00 dtlogin
 8 S 1001   483   480  IA  59      ?  184       ? pts/3    0:00 csh
 8 S 1001   446   436  IA  59      ?  292       ? ?        0:00 fbconsol
 8 S 1001   436   435  IA  59      ?  240       ? ?        0:00 Xsession
 8 S    0   435   417  IA  59      ?  662       ? ?        0:00 dtlogin
 8 S 1001   450     1  IA  59      ?  639       ? ?        0:00 speckeys
 8 S 1001   499   483  IA  49      ?  999       ? pts/3    0:00 dtsessio
 8 S 1001   507   499  IA  49      ? 1097       ? ?        0:00 dtfile
 8 S 1001   480   436  IA  59      ?  496       ? pts/3    0:00 sdt_shel
 8 S 1001   481     1  IA  59      ?  295       ? ?        0:00 dsdm
 8 O 1001   555   522  IA  59      ?  138         pts/4    0:00 ps
 8 S    0   419   391  TS  59      ?  288       ? ?        0:00 mibiisa
 8 S    0   401     1  TS  59      ?  384       ? ?        0:00 dmispd
 8 S    0   415     1  TS  59      ?  331       ? ?        0:00 sshd
 8 S    0   402     1  TS  59      ?  439       ? ?        0:00 snmpXdmi
 8 S    0   395     1  TS  59      ?  621       ? ?        0:00 dtlogin
 8 S    0   418   395  IA  59      ?  292       ? ??       0:00 fbconsol
 8 S    0   391     1  TS  59      ?  268       ? ?        0:00 snmpdx
 8 S    0   412     1  TS  59      ?  217       ? console  0:00 ttymon
 8 S 1001   498     1  IA  59      ?  574       ? pts/3    0:00 ttsessio
 8 S    0   500   155  TS  59      ?  427       ? ?        0:00 rpc.ttdb
 8 S 1001   506   499  IA  59      ? 1158       ? ?        0:02 dtwm
 8 S 1001   528   509  IA  59      ?  180       ? pts/6    0:00 csh
 8 R 1001   509   499  IA  59      ? 1004       ? ?        0:00 dtterm
 8 S 1001   510   499  IA  59      ?  921       ? ?        0:00 sdtperfm
 8 S 1001   518   498  IA  59      ?  137       ? pts/3    0:00 sh
 8 S 1001   512     1  IA  59      ?  239       ? ?        0:00 sdtvolch
 8 S 1001   519   518  IA  49      ?  907       ? pts/3    0:00 dtpad
 8 S 1001   545   507  IA  49      ? 1097       ? ?        0:00 dtfile
 8 S    0   520   155  TS  59      ?  230       ? ?        0:00 rpc.rsta
 8 S 1001   522   509  IA  59      ?  180       ? pts/4    0:00 csh
 8 S 1001   525   509  IA  59      ?  180       ? pts/5    0:00 csh
 8 S 1001   531   509  IA  59      ?  180       ? pts/7    0:00 csh
 8 S 1001   544   512  IA  59      ?  122       ? ?        0:00 cat
 8 S    0   546     1  TS  59      ?  565       ? ?        0:00 sendmail
 8 S   25   547     1  TS  59      ?  561       ? ?        0:00 sendmail
mopoke%

You can also use the /usr/sbin/dispadmin -l command to display process scheduler information.

The following example shows the output from the dispadmin -l command.


castle% /usr/sbin/dispadmin -l
CONFIGURED CLASSES
==================

SYS     (System Class)
TS      (Time Sharing)
IA      (Interactive)
castle%

For complete information, refer to the dispadmin(1M) manual page.

Designating a Process Priority

Use the following steps to designate a process priority.

  1. Become superuser.

  2. graphics/new.gif Type priocntl -e -c class -m userlimit -p priority command-name and press Return.

    The -e option executes the command. The -c class option specifies the class with which to run the process. Valid classes are TS (timesharing), RT (real time), IA (interactive), FSS (fair share), or FX (fixed priority). The -m userlimit option specifies the maximum amount you can raise or lower your priority with the -p option. The - p pri option enables you to specify the relative priority in the RT class for a real-time thread. For a timesharing process, you can specify the user-supplied priority, which ranges from -60 to +60. The command operand specifies the name of the command for which you want to change the process priority.

  3. While the process is running, in another terminal window, type ps -ecl | grep command-name and press Return.

  4. Review the output of the PRI column to verify that you have changed the process status successfully.

The following example starts the find command with the highest possible user-supplied priority.


# priocntl -e-c TS -m 60 -p 60 find . -name core -print
mopoke%
mopoke% ps -ecl | grep find
 8 S     0   686   682   TS  60     ?  133      ? pts/7    0:00 find
mopoke%



Changing the Class of a Process

Use the following steps to change the class of a process.

NOTE. You must be superuser or working in a real-time shell to change the class of a process from or to realtime.


  1. Become superuser.

  2. Type priocntl -s -c class -i id-type id-list and press Return.

    The -s option enables you to set the upper limit on the user priority range and change the current priority. The -c class option specifies the class, TS or RT, to which you are changing the process. The - i id-type and id-list options use a combination of id-type and id-list to identify the process. The id-type specifies the type of ID, such as PID or UID.

  3. While the process is running, in another terminal window, type ps -ecl | grep command-name and press Return.

  4. Review the output of the PRI column to verify that you have changed the process status successfully.

graphics/new.gif

The following example changes all the processes belonging to user 1001 to timeshare processes.


# priocntl -s -c TS -i uid 1001
# ps -ecl | grep 1001
 8 S  1001  496  481  TS 59      ?  137      ? pts/4  0:00 sh
 8 S  1001  497  496  TS 59      ?  152      ? pts/4  0:00 more
 8 S  1001  329  308  TS 59      ?  3801     ? ?      0:35 Xsun
 8 S  1001  350  332  TS 59      ?  241      ? ?      0:00 Xsession
 8 S  1001  408    1  TS 59      ?  590      ? pts/3  0:00 ttsessio
 8 S  1001  360  350  TS 59      ?  297      ? ?      0:00 fbconsol
 8 S  1001  417  409  TS 59      ?  1105     ? ?      0:00 dtfile
 8 S  1001  364    1  TS 59      ?  326      ? ?      0:00 speckeys
 8 S  1001  394  391  TS 59      ?  182      ? pts/3  0:00 csh
 8 S  1001  391  350  TS 59      ?  501      ? pts/3  0:00 sdt_shel
 8 S  1001  392    1  TS 59      ?  300      ? ?      0:00 dsdm
 8 S  1001  409  394  TS 59      ?  1015     ? pts/3  0:00 dtsessio
 8 S  1001  416  409  TS 59      ?  1176     ? ?      0:03 dtwm
 8 S  1001  418  409  TS 59      ?  977      ? ??     0:01 dtterm
 8 S  1001  430  418  TS 59      ?  180      ? pts/4  0:00 csh
 8 S  1001  420  409  TS 59      ?  929      ? ?      0:00 sdtperfm
 8 S  1001  450  417  TS 59      ?  1105     ? ?      0:00 dtfile
 8 S  1001  422  408  TS 59      ?  137      ? pts/3  0:00 sh
 8 S  1001  423  422  TS 59      ?  913      ? pts/3  0:00 dtpad
 8 S  1001  424    1  TS 59      ?  240      ? ?      0:00 sdtvolch
 8 S  1001  455  424  TS 59      ?  122      ? ?      0:00 cat
 8 S  1001  435  418  TS 59      ?  180      ? pts/5  0:00 csh
 8 S  1001  439  418  TS 59      ?  180      ? pts/6  0:00 csh
 8 S  1001  442  418  TS 59      ?  182      ? pts/7  0:00 csh
 8 S  1001  481  430  TS 59      ?  131      ? pts/4  0:00 man
 8 S  1001  545  442  TS 59      ?  517      ? pts/7  0:03 spider.e
 8 S  1001  690  439  TS 59      ?  235      ? pts/6  0:00 ftp
 8 S  1001  610  608  TS 59      ?  2574     ? ?      0:00 .netscap
 8 S  1001  607    1  TS 59      ?  630      ? ?      0:00 netscape
 8 S  1001  609  607  TS 59      ?  653      ? ?      0:00 netscape
 8 S  1001  608  607  TS 59      ?  3165     ? ?      0:20 .netscap
#



Setting Fair-Share Parameters
graphics/new.gif

The valid class-specific options for setting fair-share parameters—new in the Solaris 9 release—are shown in Table 15.

Table 15. Options to the Fair-Share Class of the priocntl Command

Option

Description

-m fssuprilim

Set the user-priority limit of the specified process(es) to fssuprilim.

-p fssupri

Set the user priority of the specified process(es) to fssupri.

Setting Fixed-Priority Parameters
graphics/new.gif

The valid class-specific options for setting fixed-priority parameters—new in the Solaris 9 release—are shown in Table 16.

Table 16. Options to the Fixed-Priority Class of the priocntl Command

Option

Description

-m fxuprilim

Set the user-priority limit of the specified process(es) to fxuprilim.

-p fxupri

Set the user priority of the specified process(es) to fxupri.

-t tqntm [-r res]

Set the time quantum of the specified process(es) to tqntm. You can optionally specify a resolution.

Use the following steps to assign a fixed priority to a command.

  1. Become superuser.

  2. Type priocntl -e -c class -m fxuprilim -p fxupri -t tqntm command and press Return.

    The -e option enables you to execute a specific command with the class and scheduling parameters associated with a set of processes. The -c class option specifies the class, in this case, FX for fixed priority, to which you are changing the process. The - m fxuprilim option specifies the user priority limit of the specified processes. The - p fxupri option specifies the user priority of the specified processes. The - t tqntm option specifies time quantum of the specified processes. The command argument specifies the command to which to apply the fixed-priority options.

The following example executes a command in the fixed-priority class with a user-priority limit of 20, a user priority of 10, and a time quantum of 250 milliseconds.


mopoke% su
Password:
# priocntl -e -c FX -m 20 -p 10 -t 250 ps -ef | grep priocntl
    root 701 674 0 01:01:52 pts/4 0:00 grep priocntl
#




Setting the Priority of a Process (nice)

graphics/new.gif

NOTE. The nice command is supported only for backward compatibility with previous Solaris releases. Use the priocntl command to manage process priorities.


graphics/new.gif

The priority of a process is determined by the policies of its scheduling class and by its nice number. The global priority of each timesharing process is calculated by adding the user-supplied priority and the system-calculated priority. You can modify only the user-supplied priority. You can view the nice number of a process in the NI column of the output of the ps -l command.

graphics/new.gif

The range of nice numbers is between 0 and +40, with 0 the highest priority. The default value is 20.

You can use the priocntl command (preferred) or the nice command to raise or lower the priority of a command or a process. When you use the nice command without an argument, the default is to increase the nice number by four units, thus lowering the priority of the process.

NOTE. You must be superuser to raise the priority of a process with the nice command. Users can lower their own process priorities.


Use the following command to lower the priority of a command by four units (the default).


/usr/bin/nice command-name

Use the following command to lower the priority of a command by increasing the nice number by ten units.


/usr/bin/nice -n +10 command-name

NOTE. The plus sign (+) is optional for positive numbers. The minus sign (–) is required for negative numbers.


Use the following command to raise the priority of a command by lowering the nice number by ten units.


/usr/bin/nice -10 command-name

Use the following command to raise the priority of a command by lowering the nice number by ten units. The minus sign indicates a negative number.


/usr/bin/nice -10 command-name



Changing the Priority of a Running Process (renice)

If you want to alter the scheduling priority of one or more running processes, you can use the renice command. Specify the process IDs of the processes to be affected. If the first operand is a number within the range of priorities (–20 to 20), renice treats it as a priority. Otherwise, renice treats it as an ID.

Users other than superuser can alter the priority only of processes they own and can increase their nice value only within the range 0 to 19.

The following example adjusts the system scheduling priority so that process IDs 987 and 32 have a lower scheduling priority.


paperbark% renice -n 5 -p 987 32
paperbark%

The -n option specifies the system scheduling priority, and the -p option specifies the process ID numbers to adjust.

Finding or Signalling Processes (pgrep, pkill)

You can use the pgrep command to examine the active processes on the system and report the process IDs of the processes whose attributes match the command-line argument. The simplest way to use pgrep is to type the command with the name of the process as the argument.


pgrep process-name

Refer to the pgrep(1) manual page for a complete listing of options and arguments.

The following example uses pgrep to find the process ID of the sendmail command.


paperbark% pgrep sendmail
2830
paperbark%

The pkill command works in the same way as pgrep except that it signals each matching process as would kill(1) instead of displaying the process ID. You can specify a signal name or number as the first command-line option to pkill.

Refer to the pgrep(1) manual page for a complete listing of options and arguments for pkill.

The following example terminates the most recently created xterm.


paperbark% pkill -n xterm
paperbark%



    [ Team LiB ] Previous Section Next Section