System Administration Guide

Chapter 63 Managing Processes (Tasks)

This chapter describes the procedures for managing system processes. This is a list of the step-by-step instructions in this chapter.

Displaying Information About Processes

This section describes commands used to manage process information.

The ps Command

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:

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.  

How to List Processes

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. 

Example--Listing Processes

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

Displaying Information About Processes (/proc Tools)

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 


Note -

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).


How to Display Information About Processes

  1. (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.

  2. 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. 

Examples--Displaying Information About Processes

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.


 [Adds the /usr/proc/bin directory to
the PATH variable. ] # PATH=$PATH:/usr/proc/bin
# export PATH
 [Obtains the process identification number for lpsched. ] # ps -e | grep lpsched
   191 ?        0:00 /usr/lib/lpsched
 [Displays the current working directory for lpsched.] # pwdx 191
 
191:    /
 [	Displays the process tree containing lpsched. ] # ptree 191
 
183   /usr/lib/lpsched
 [Displays fstat and fcntl
information. ] # pfiles 191
210:    /usr/lib/lpsched
  Current rlimit: 1024 file descriptors
   0: S_IFIFO mode:0000 dev:165,0 ino:83 uid:0 gid:0 size:0
      O_RDWR
   1: S_IFIFO mode:0000 dev:165,0 ino:83 uid:0 gid:0 size:0
      O_RDWR
   3: S_IFCHR mode:0666 dev:32,24 ino:34307 uid:0 gid:3 rdev:21,0
      O_WRONLY FD_CLOEXEC
   4: S_IFDOOR mode:0444 dev:171,0 ino:4124226512 uid:0 gid:0 
      size:0
      O_RDONLY|O_LARGEFILE FD_CLOEXEC  door to nscd[200]
   5: S_IFREG mode:0664 dev:32,24 ino:311 uid:71 gid:8 size:0
      O_WRONLY

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
 

Controlling Processes (/proc Tools)

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 


Note -

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).


How to Control Processes

  1. (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.

  2. 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. 

  3. Verify the process status using the ps command.


    # ps | grep PID
    

Example--Controlling Processes

The following example shows how to use process tools to stop and restart Print Tool.


 [Adds the /usr/proc/bin directory to
the PATH variable.] # PATH=$PATH:/usr/proc/bin
# export PATH
 [Obtains the process identification number for Print Tool. ] # ps -e | grep print*
264 console 0:03 printtool
 [Stops the Print Tool process. ] # pstop 264
  [Restarts the Print Tool process. ] # prun 264
# ps | grep 264
264 console 0:03 printtool
#

Killing a Process (kill)

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.

How to Kill a Process

  1. (Optional) To kill a process belonging to another user, become superuser.

  2. (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.

  3. 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.  

  4. Use the ps command to verify that the process has been stopped.


    $ ps -ef | grep PID ...
    

Managing Process Class Information

The listing below shows which classes are configured on your system, and the user priority range for the timesharing class. The possible classes are:

Changing the Scheduling Priority of Processes With priocntl

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.

How to Display Basic Information About Process Classes

You can display process class and scheduling parameters with the priocntl -l command.


$ priocntl -l

Example--Getting Basic Information About Process Classes

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
 

How to Display the Global Priority of a Process

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.

Example--Displaying the Global Priority of a Process

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
 

How to Designate a Process Priority

  1. Become superuser.

  2. 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.

  3. Verify the process status by using the ps -ecl command.


    # ps -ecl | grep command_name
    

Example--Designating a Priority

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

How to Change Scheduling Parameters of a Timeshare Process

  1. Become superuser.

  2. 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.

  3. Verify the process status by using the ps --ecl command.


    # ps -ecl | grep idlist

Example--Changing Scheduling Parameters of a Timeshare 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.


# priocntl -e -c RT -t 500 -p 20 myprog
# ps -ecl | grep myprog

How to Change the Class of a Process

  1. (Optional) Become superuser.


    Note -

    You must be superuser or working in a real-time shell to change processes from, or to, real-time processes.


  2. 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.

  3. Verify the process status by using the ps -ecl command.


    # ps -ecl | grep idlist
    

Example--Changing the Class of a Process

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

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).


Changing the Priority of a Timesharing Process With nice

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.

How to Change the Priority of a Process

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.

Process Troubleshooting

Here are some tips on obvious problems you may find: