System Administration Guide: Advanced Administration

Chapter 12 Managing System Processes (Tasks)

This chapter describes the procedures for managing system processes.

For information on the procedures associated with managing system processes, see the following:

For overview information about managing system processes, see the following:

Managing System Processes (Task Map)

Task 

Description 

For Instructions 

List processes. 

Use the ps command to list all the processes on a system.

How to List Processes

Display information about processes. 

Use the pgrep command to obtain the process IDs for processes that you want to display more information about.

How to Display Information About Processes

Control processes. 

Locate processes by using the pgrep command. Then, use the appropriate pcommand (/proc) to control the process. See Table 12–3 for a description of the (/proc) commands.

How to Control Processes

Kill a process. 

 

Locate a process, either by process name or process ID. You can use either the pkill or kill commands to terminate the process.

 

How to Terminate a Process (pkill)

How to Terminate a Process (kill)

Commands for Managing System Processes

The following table describes the commands for managing system processes.

Table 12–1 Commands for Managing Processes

Command  

Description 

Man Page 

ps, pgrep, prstat, pkill

Checks the status of active processes on a system, as well as displays detailed information about the processes. 

ps(1), pgrep(1), andprstat(1M)

pkill

Functions identically to pgrep but finds or signals processes by name or other attribute and terminates the process. Each matching process is signaled as if by the kill command, instead of having its process ID printed.

pgrep(1), and pkill(1)

kill(1)

pargs, preap

Assists with processes debugging. 

pargs(1), and preap(1)

dispadmin

Lists default process scheduling policies. 

dispadmin(1M)

priocntl

Assigns processes to a priority class and manages process priorities. 

priocntl(1)

nice

Changes the priority of a timesharing process. 

nice(1)

psrset

Binds specific process groups to a group of processors rather than to just a single processor. 

psrset(1M)

The Solaris Management Console's Processes tool enables you to manage processes with a user-friendly interface. For information on using and starting the Solaris Management Console, see Chapter 2, Working With the Solaris Management Console (Tasks), in System Administration Guide: Basic Administration.

Using 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 administrative tasks such as determining how to set process priorities.

Depending on which options you use, the ps command reports the following information:

The following table describes some fields that are reported by the ps command. Which fields are displayed depend on which option you choose. For a description of all available options, see the ps(1) man page.

Table 12–2 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 ID. 

C

The processor xutilization for scheduling. This field is not displayed when the -c option is used.

CLS

The scheduling class to which the process belongs such as real-time, system, or timesharing. This field is included only with the -c option.

PRI

The kernel thread's scheduling priority. Higher numbers indicate a 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 that 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.  

Using the /proc File System and Commands

You can display detailed information about the processes that are listed in the /proc directory by using process commands. The following table lists the /proc process commands. The /proc directory is also known as the process file system (PROCFS). Images of active processes are stored here by their process ID number.

Table 12–3 Process Commands (/proc)

Process Command 

Description 

pcred

Displays process credential information 

pfiles

Reports fstat and fcntl information for open files in a process

pflags

Prints /proc tracing flags, pending signals and held signals, and other status information

pldd

Lists the dynamic libraries that are linked into a process 

pmap

Prints the address space map of each process 

psig

Lists the signal actions and handlers of each process 

prun

Starts each process 

pstack

Prints a hex+symbolic stack trace for each lwp in each process 

pstop

Stops each process 

ptime

Times a process by using microstate accounting 

ptree

Displays the process trees that contain the process 

pwait

Displays status information after a process terminates 

pwdx

Displays the current working directory for a process 

For more information, see proc(1).

The process tools are similar to some options of the ps command, except that the output that is provided by these commands is more detailed.

In general, the process commands do the following:

Managing Processes With Process Commands (/proc)

You can display detailed, technical information about processes or control active processes by using some of the process commands. Table 12–3 lists some of the /proc commands.

If a process becomes trapped in an endless loop, or if the process takes too long to execute, you might want to stop (kill) the process. For more information about stopping processes using the kill or the pkill command, see Chapter 12, Managing System Processes (Tasks).

The /proc file system is a directory hierarchy that contains additional subdirectories for state information and control functions.

The /proc file system also provides an xwatchpoint facility that is used to remap read-and-write permissions on the individual pages of a process's address space. This facility has no restrictions and is MT-safe.

Debugging tools have been modified to use /proc's xwatchpoint facility, which means that the entire xwatchpoint process is faster.

The following restrictions have been removed when you set xwatchpoints by using the dbx debugging tool:

For more information, see the proc(4), and mdb(1) man pages.

ProcedureHow to List Processes

  1. Use the ps command to list all the processes on a system.


    $ ps [-efc]
    ps

    Displays only the processes that are associated with your login session.

    -ef

    Displays full information about all the processes that are being executed on the system.

    -c

    Displays process scheduler information.


Example 12–1 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 the ps -ef command. This output shows that the first process that is 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   Dec 20 ?        0:17 sched
    root     1     0  0   Dec 20 ?        0:00 /etc/init -
    root     2     0  0   Dec 20 ?        0:00 pageout
    root     3     0  0   Dec 20 ?        4:20 fsflush
    root   374   367  0   Dec 20 ?        0:00 /usr/lib/saf/ttymon
    root   367     1  0   Dec 20 ?        0:00 /usr/lib/saf/sac -t 300
    root   126     1  0   Dec 20 ?        0:00 /usr/sbin/rpcbind
    root    54     1  0   Dec 20 ?        0:00 /usr/lib/sysevent/syseventd
    root    59     1  0   Dec 20 ?        0:00 /usr/lib/picl/picld
    root   178     1  0   Dec 20 ?        0:03 /usr/lib/autofs/automountd
    root   129     1  0   Dec 20 ?        0:00 /usr/sbin/keyserv
    root   213     1  0   Dec 20 ?        0:00 /usr/lib/lpsched
    root   154     1  0   Dec 20 ?        0:00 /usr/sbin/inetd -s
    root   139     1  0   Dec 20 ?        0:00 /usr/lib/netsvc/yp/ypbind ...
    root   191     1  0   Dec 20 ?        0:00 /usr/sbin/syslogd
    root   208     1  0   Dec 20 ?        0:02 /usr/sbin/nscd
    root   193     1  0   Dec 20 ?        0:00 /usr/sbin/cron
    root   174     1  0   Dec 20 ?        0:00 /usr/lib/nfs/lockd
  daemon   175     1  0   Dec 20 ?        0:00 /usr/lib/nfs/statd
    root   376     1  0   Dec 20 ?        0:00 /usr/lib/ssh/sshd
    root   226     1  0   Dec 20 ?        0:00 /usr/lib/power/powerd
    root   315     1  0   Dec 20 ?        0:00 /usr/lib/nfs/mountd
    root   237     1  0   Dec 20 ?        0:00 /usr/lib/utmpd
    .
    .
    .    

ProcedureHow to Display Information About Processes

  1. Obtain the process ID of the process that you want to display more information about.


    # pgrep process
    

    where process is the name of the process you want to display more information about.

    The process ID is displayed in the first column of the output.

  2. Display the process information that you need.


    # /usr/bin/pcommand pid
    
    pcommand

    Is the (/proc) command that you want to run. Table 12–3 lists and describes these commands.

    pid

    Identifies the process ID.


Example 12–2 Displaying Information About Processes

The following example shows how to use process commands to display more information about a cron process.


# pgrep cron 1
4780
# pwdx 4780 2
4780:   /var/spool/cron/atjobs
# ptree 4780 3
4780  /usr/sbin/cron
# pfiles 4780 4
4780:   /usr/sbin/cron
  Current rlimit: 256 file descriptors
   0: S_IFCHR mode:0666 dev:290,0 ino:6815752 uid:0 gid:3 rdev:13,2
      O_RDONLY|O_LARGEFILE
      /devices/pseudo/mm@0:null
   1: S_IFREG mode:0600 dev:32,128 ino:42054 uid:0 gid:0 size:9771
      O_WRONLY|O_APPEND|O_CREAT|O_LARGEFILE
      /var/cron/log
   2: S_IFREG mode:0600 dev:32,128 ino:42054 uid:0 gid:0 size:9771
      O_WRONLY|O_APPEND|O_CREAT|O_LARGEFILE
      /var/cron/log
   3: S_IFIFO mode:0600 dev:32,128 ino:42049 uid:0 gid:0 size:0
      O_RDWR|O_LARGEFILE
      /etc/cron.d/FIFO
   4: S_IFIFO mode:0000 dev:293,0 ino:4630 uid:0 gid:0 size:0
      O_RDWR|O_NONBLOCK
   5: S_IFIFO mode:0000 dev:293,0 ino:4630 uid:0 gid:0 size:0
      O_RDWR
  1. Obtains the process ID for the cron process

  2. Displays the current working directory for the cron process

  3. Displays the process tree that contains the cron process

  4. Displays fstat and fcntl information


ProcedureHow to Control Processes

  1. Obtain the process ID of the process that you want to control.


    # pgrep process
    

    where process is the name of the process you want to control.

    The process ID displayed in the first column of the output.

  2. Use the appropriate process command to control the process.


    # /usr/bin/pcommand pid
    
    pcommand

    Is the process (/proc) command that you want to run. Table 12–3 lists and describes these commands.

    pid

    Identifies the process ID.

  3. Verify the process status.


    # ps -ef | grep pid
    

Example 12–3 Controlling Processes

The following example shows how to use process command to stop and restart the dtpad process.


# pgrep dtpad 1
2921
# pstop 29212 
# prun 2921 3
  1. Obtains the process ID for the dtpad process

  2. Stops the dtpad process

  3. Restarts the dtpad process


Terminating a Process (pkill, kill)

Sometimes, you might need to stop (kill) a process. The process might be in an endless loop. Or, you might have started a large job that you want to stop before it is completed. You can kill any process that you own. Superuser can kill any process in the system except for those processes with process IDs of 0, 1, 2, 3, and 4. Killing these processes most likely will crash the system.

For more information, see the pgrep(1) and pkill(1) and kill(1) man pages.

ProcedureHow to Terminate a Process (pkill)

  1. (Optional) To terminate the process of another user, become superuser or assume an equivalent role.

  2. Obtain the process ID for the process that you want to terminate.


    $ pgrep process
    

    where process is the name of the process that you want to terminate.

    For example:


    $ pgrep netscape
    587
    566

    The process ID is displayed in the output.


    Note –

    To obtain process information on a Sun Ray, use the following commands:


    # ps -fu user
    

    This command lists all user processes.


    # ps -fu user | grep process
    

    This command locates a specific process for a user.


  3. Terminate the process.


    $ pkill [signal] process
    
    signal

    When no signal is included in the pkill command-line syntax, the default signal that is used is –15 (SIGKILL). Using the –9 signal (SIGTERM) with the pkill command ensures that the process terminates promptly. However, the –9 signal should not be used to kill certain processes, such as a database process, or an LDAP server process. The result is that data might be lost.

    process

    Is the name of the process to stop.


    Tip –

    When using the pkill command to terminate a process, first try using the command by itself, without including a signal option. Wait a few minutes to see if the process terminates before using the pkill command with the -9 signal.


  4. Verify that the process has been terminated.


    $ pgrep process
    

    The process you terminated should no longer be listed in the output of the pgrep command.

ProcedureHow to Terminate a Process (kill)

  1. (Optional) To terminate the process of another user, become superuser or assume an equivalent role.

  2. Obtain the process ID of the process that you want to terminate.


    $ ps -fu user
    

    where user is the user that you want to display processes for.

    The process ID is displayed in the first column of the output.

  3. Terminate the process.


    $ kill [signal-number] pid
    
    signal

    When no signal is included in the kill command-line syntax, the default signal that is used is –15 (SIGKILL). Using the –9 signal (SIGTERM) with the kill command ensures that the process terminates promptly. However, the –9 signal should not be used to kill certain processes, such as a database process, or an LDAP server process. The result is that data might be lost.

    pid

    Is the process ID of the process that you want to terminate.


    Tip –

    When using the kill command to stop a process, first try using the command by itself, without including a signal option. Wait a few minutes to see if the process terminates before using the kill command with the -9 signal.


  4. Verify that the process has been terminated.


    $ pgrep pid
    

    The process you terminated should no longer be listed in the output of the pgrep command.

Debugging a Process (pargs, preap)

The pargs command and the preap command improve process debugging. The pargs command prints the arguments and environment variables associated with a live process or core file. The preap command removes defunct (zombie) processes. A zombie process has not yet had its exit status claimed by its parent. These processes are generally harmless but can consume system resources if they are numerous. You can use the pargs and preap commands to examine any process that you have the privileges to examine. As superuser, you can examine any process.

For information on using the preap command, see the preap(1) man page. For information on the using the pargs command, see the pargs(1) man page. See also, the proc(1) man page.


Example 12–4 Debugging a Process (pargs)

The pargs command solves a long-standing problem of being unable to display with the ps command all the arguments that are passed to a process. The following example shows how to use the pargs command in combination with the pgrep command to display the arguments that are passed to a process.


# pargs `pgrep ttymon`
579:	/usr/lib/saf/ttymon -g -h -p system-name console login:  
-T sun -d /dev/console -l 
argv[0]: /usr/lib/saf/ttymon
argv[1]: -g
argv[2]: -h
argv[3]: -p
argv[4]: system-name console login: 
argv[5]: -T
argv[6]: sun
argv[7]: -d
argv[8]: /dev/console
argv[9]: -l
argv[10]: console
argv[11]: -m
argv[12]: ldterm,ttcompat
548:	/usr/lib/saf/ttymon
argv[0]: /usr/lib/saf/ttymon

The following example shows how to use the pargs -e command to display the environment variables that are associated with a process.


$ pargs -e 6763
6763: tcsh
envp[0]: DISPLAY=:0.0

Managing Process Class Information (Task Map)

Task 

Description 

For Instructions 

Display basic information about process classes. 

Use the priocntl -l command. to Display process scheduling classes and priority ranges.

How to Display Basic Information About Process Classes (priocntl)

Display the global priority of a process. 

Use the ps -ecl command to display the global priority of a process.

How to Display the Global Priority of a Process

Designate a process priority. 

Start a process with a designated priority by using the priocntl -e -c command.

How to Designate a Process Priority (priocntl)

Change scheduling parameters of a timesharing process. 

Use the priocntl -s -m command to change scheduling parameters in a timesharing process.

How to Change Scheduling Parameters of a Timesharing Process (priocntl)

Change the class of a process. 

Use the priocntl -s -c command to change the class of a process.

How to Change the Class of a Process (priocntl)

Change the priority of a process. 

Use the /usr/bin/nice command with the appropriate options to lower or raise the priority of a process.

How to Change the Priority of a Process (nice)

Managing Process Class Information

The following list identifies the process scheduling classes that can be configured on your system. Also included is the user priority range for the timesharing class.

The possible process scheduling classes are as follows:

Changing the Scheduling Priority of Processes (priocntl)

The scheduling priority of a process is the priority assigned by the process scheduler, according to scheduling policies. The dispadmin command lists the default scheduling policies. For more information, see the dispadmin(1M) man page.

You can use the priocntl command to assign processes to a priority class and to manage process priorities. For instructions on using the priocntl command to manage processes, see How to Designate a Process Priority (priocntl).

ProcedureHow to Display Basic Information About Process Classes (priocntl)

  1. Display process scheduling classes and priority ranges with the priocntl -l command.


    $ priocntl -l
    

Example 12–5 Displaying Basic Information About Process Classes (priocntl)

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: -60 through 60

FX (Fixed priority)
        Configured FX User Priority Range: 0 through 60

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

ProcedureHow to Display the Global Priority of a Process

  1. Display the global priority of a process by using the ps command.


    $ ps -ecl
    

    The global priority is listed under the PRI column.


Example 12–6 Displaying the Global Priority of a Process

The following example shows ps -ecl command output. The values in the PRI column show that the pageout process has the highest priority, while the sh process has the lowest priority.


$ 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

ProcedureHow to Designate a Process Priority (priocntl)

  1. Become superuser or assume an equivalent role.

    Roles contain authorizations and privileged commands. For more information about roles, see Configuring RBAC (Task Map) in System Administration Guide: Security Services.

  2. Start a process with a designated priority.


    # priocntl -e -c class -m user-limit -p pri command-name
    
    -e

    Executes the command.

    -c class

    Specifies the class within which to run the process. The valid classes are TS (timesharing), RT (real time), IA (interactive), FSS (fair share), and FX (fixed priority).

    -m user-limit

    When you use the -p option, specifies the maximum amount you can raise or lower your priority,

    -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 -60 to +60.

  3. Verify the process status.


    # ps -ecl | grep command-name
    

Example 12–7 Designating a Process Priority (priocntl)

The following example shows how to start the find command with the highest possible user-supplied priority.


# priocntl -e -c TS -m 60 -p 60 find . -name core -print
# ps -ecl | grep find

ProcedureHow to Change Scheduling Parameters of a Timesharing Process (priocntl)

  1. Become superuser or assume an equivalent role.

    Roles contain authorizations and privileged commands. For more information about roles, see Configuring RBAC (Task Map) in System Administration Guide: Security Services.

  2. Change the scheduling parameters of a running timesharing process.


    # priocntl -s -m user-limit [-p user-priority] -i idtype idlist
    
    -s

    Lets you set the upper limit on the user priority range and change the current priority.

    -m user-limit

    When you use the -p option, specifies the maximum amount you can raise or lower the priority.

    -p user-priority

    Allows you to designate a priority.

    -i xidtype xidlist

    Uses a combination of xidtype and xidlist to identify the process or processes. The xidtype specifies the type of ID, such as the process ID or the user ID. Use xidlist to identify a list of process IDs or user IDs.

  3. Verify the process status.


    # ps -ecl | grep idlist
    

Example 12–8 Changing Scheduling Parameters of a Timesharing Process (priocntl)

The following example shows how to execute 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 -m 500 -p 20 myprog
# ps -ecl | grep myprog

ProcedureHow to Change the Class of a Process (priocntl)

  1. (Optional) Become superuser or assume an equivalent role.

  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 for time-sharing or RT for real-time, to which you are changing the process.

    -i idtype idlist

    Uses a combination of xidtype and xidlist to identify the process or processes. The xidtype specifies the type of ID, such as the process ID or user ID. Use xidlist to identify a list of process IDs or user IDs.


    Note –

    You must be superuser or working in a real-time shell to change a process from, or to, a real-time process. If, as superuser, you change a user process to the real-time class, the user cannot subsequently change the real-time scheduling parameters by using the priocntl -s command.


  3. Verify the process status.


    # ps -ecl | grep idlist
    

Example 12–9 Changing the Class of a Process (priocntl)

The following example shows how to change all the processes that belong to user 15249 to real-time processes.


# priocntl -s -c RT -i uid 15249
# ps -ecl | grep 15249

Changing the Priority of a Timesharing Process (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. The global priority 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. The priority number is determined by several factors, including the process's scheduling 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. However, only superuser can lower a nice number to increase the priority of a process. This restriction prevents users from increasing the priorities of their own processes, thereby monopolizing a greater share of the CPU.

The nice numbers range from 0 to +39, with 0 representing the highest priority. The default nice value for each timesharing process is 20. Two versions of the command are available: the standard version, /usr/bin/nice, and the C shell built-in command.

ProcedureHow to Change the Priority of a Process (nice)

Using this procedure, a user can lower the priority of a process. However, superuser can raise or lower the priority of a process.


Note –

This section describes the syntax of the /usr/bin/nice command and not the C-shell built-in nicecommand. For information about the C-shell nice command, see the csh(1) man page.


  1. Determine whether you want to change the priority of a process, either as a user or as superuser. Then, select one of the following:

    • As a user, follow the examples in Step 2 to lower the priority of a command.

    • As a superuser, follow the examples in Step 3 to raise or lower priorities of a command.

  2. As a user, lower the priority of a command by increasing the nice number.

    The following nice command executes command-name with a lower priority by raising the nice number by 5 units.


    $ /usr/bin/nice -5 command-name
    

    In the preceding command, the minus sign designates that what follows is an option. This command could also be specified as follows:


    % /usr/bin/nice -n 5 command-name
    

    The following nice command lowers the priority of command-name by raising the nice number by the default increment of 10 units, but not beyond the maximum value of 39.


    % /usr/bin/nice command-name
    
  3. As superuser or assuming an equivalent role, raise or lower the priority of a command by changing the nice number.

    The following nice command raises the priority of command-name by lowering the nice number by 10 units, but not below the minimum value of 0.


    # /usr/bin/nice --10 command-name
    

    In the preceding command, the first minus sign designates that what follows is an option. The second minus sign indicates a negative number.

    The following nice command lowers the priority of command-name by raising the nice number by 5 units, but not beyond the maximum value of 39.


    # /usr/bin/nice -5 command-name
    
See Also

For more information, see the nice(1) man page.

Troubleshooting Problems With System Processes

Here are some tips on obvious problems you might encounter: