System Administration Guide, Volume II
只搜尋這本書
以 PDF 格式下載這本書

Managing Processes

70

This chapter describes the procedures for managing system processes. This is a list of the step-by-step instructions in this chapter.
How to List Processespage 1391
How to Display Information About Processespage 1394
How to Control Processespage 1397
How to Kill a Processpage 1398
How to Display Basic Information About Process Classespage 1399
How to Display the Global Priority of a Processpage 1400
How to Designate Prioritypage 1401
How to Change Scheduling Parameters of a Timeshare Processpage 1402
How to Change the Class of a Processpage 1403
How to Change the Priority of a Processpage 1404

Displaying Information About Processes (ps)

You can check the status of active processes on a system by using the ps command. Depending on which options you use, ps reports the following information:
  • Current status of the process
  • Process ID
  • Parent process ID
  • User ID
  • Scheduling class
  • Priority
  • Address of the process
  • Memory used
  • CPU time used
Table 70-1 describes some of the fields reported by the ps command. The fields displayed depend on which option you choose. See the ps(1) man page for a description of all available options.
Table 70-1 ps
FieldDescription
UIDThe user ID of the process's owner.
PIDThe process identification number.
PPIDThe parent process's identification number.
CThe processor utilization for scheduling. This field is not displayed when the -c option is used.
CLSThe scheduling class to which the process belongs: real-time, system, or timesharing. This field is included only with the -c option.
PRIThe kernel thread's scheduling priority. Higher numbers mean higher priority.
NIThe process's nice number, which contributes to its scheduling priority. Making a process "nicer" means lowering its priority.
ADDRThe address of the proc structure.
SZThe virtual address size of the process.
WCHANThe address of an event or lock for which the process is sleeping.
STIMEThe starting time of the process (in hours, minutes, and seconds).
Table 70-1 ps(Continued)
FieldDescription
TTYThe terminal from which the process (or its parent) was started. A question mark indicates there is no controlling terminal.
TIMEThe total amount of CPU time used by the process since it began.
CMDThe 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]  

In this command,
psDisplays only the processes associated with your login session.
-efDisplays 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/automountd  
      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 -e passwd,no -e  
  group,no -e hosts,no -f /etc/nscd.conf  
      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 -g -h -p  
  saturn console login:  -T AT386 -d /dev/console -l  
      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 70-2 lists these process tools. For more detailed information, refer to the proc(1) man page.
Table 70-2 /usr/proc/bin
Process ToolWhat It Displays
pcredCredentials
pfilesfstat and fcntl information for open files in a process
pflags/proc tracing flags, pending and held signals, and other status information
plddDynamic libraries linked into a process
pmapAddress space map
psigSignal actions
pstackHex+symbolic stack trace
ptimeProcess time using microstate accounting
ptreeProcess trees that contain the process
pwaitStatus information after a process terminates
pwdxCurrent 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  

In this command,
process........Is the name of the process you want to display more information about.
The process identification number is in the first column of the output.
  1. Use the appropriate /usr/bin/proc command to display the information you need.


  $ /usr/proc/bin/pcommand PID  

In this command,
pcommandIs the process tool command you want to run. Table 70-2 lists these commands.
PIDIs the 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 lpNet process. First the /usr/proc/bin path is defined to avoid typing long process tool commands. Next, the identification number for lpNet is obtained. Finally, output from three process tool commands is shown.

  (1) $ PATH=$PATH:/usr/proc/bin  
       $ export PATH  
  (2) $ ps -e | grep lpNet  
          191 ?        0:00 lpNet  
  (3) $ pwdx 191  
       191:    /var/spool/lp  
  (4) #$ ptree 191  
       183   /usr/lib/lpsched  
         191   lpNet  
  (5) $ pfiles 191  
       191:    lpNet  
         Current rlimit: 1024 file descriptors  
          0: S_IFCHR mode:0666 dev:102,0 ino:23278 uid:0 gid:3 rdev:13,2  
             O_RDWR  
          1: S_IFCHR mode:0666 dev:102,0 ino:23278 uid:0 gid:3 rdev:13,2  
             O_RDWR  
          2: S_IFCHR mode:0666 dev:102,0 ino:23278 uid:0 gid:3 rdev:13,2  
             O_RDWR  
          3: S_IFIFO mode:0000 dev:159,0 ino:65 uid:0 gid:0 size:0  
             O_RDWR  
          4: S_IFREG mode:0666 dev:102,0 ino:14900 uid:0 gid:0 size:105  
             O_RDWR|O_APPEND  
          5: S_IFREG mode:0664 dev:102,0 ino:17007 uid:71 gid:8 size:2141  
             O_RDONLY  
          6: S_IFIFO mode:0000 dev:159,0 ino:66 uid:0 gid:0 size:0  
             O_RDWR  
          7: S_IFIFO mode:0000 dev:159,0 ino:66 uid:0 gid:0 size:0  
             O_RDWR  
          8: S_IFIFO mode:0000 dev:159,0 ino:67 uid:0 gid:0 size:0  
             O_RDWR  
          9: S_IFIFO mode:0000 dev:159,0 ino:67 uid:0 gid:0 size:0  
             O_RDWR  
         10: ??? mode:0444 dev:165,0 ino:2 uid:0 gid:0 size:0  
             O_RDONLY close-on-exec  

(1)

Adds the /usr/proc/bin directory to the PATH variable.

(2)Obtains the process identification number for lpNET.

(3)Displays the current working directory for lpNET. (4) Displays the process tree containing lpNET. (5) Displays fstat and fcntl information.

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 70-3 lists these process tools. For more detailed information, refer to the proc(1) man page.
Table 70-3 /usr/proc/bin
Process ToolWhat it Does
pstopStops a process
prunRestarts 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  

In this command,
process........Is the name of the process you want to display more information about.
The process identification number is in the first column of the output.
  1. Use the appropriate /usr/proc/bin command to control the process.


  $ /usr/proc/bin/pcommand PID  

In this command,
pcommandIs the process tool command you want to run. Table 70-3 lists these commands.
PIDIs the identification number of a process.

Example--Controlling Processes

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

  (1) $ PATH=$PATH:/usr/proc/bin  
       $ export PATH  
  (2) $ ps -e | grep print*  
       264 console 0:03 printtoo  
  (3) $ pstop 264  
  (4) $ prun 264  

(1)

Adds the /usr/proc/bin directory to the PATH variable.

(2)Obtains the process identification number for Print Tool.

(3)Stops the Print Tool process. (4)Restarts the Print Tool process.

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 root can kill any processes in the system except for those with process IDs 0, 1, 2, 3, and 4.
For detailed information, refer to the kill(1) man page.

· How to Kill a Process

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

  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  

In this command,
process........Is the name of the process you want to display more information about.
The process identification number is in the first column of the output.
  1. Use the kill command to stop the process.


  $ kill [-9] PID . . .  

In this command,
-9Ensures that the process terminates promptly.
PID . . .Is the ID of the process or processes to stop.

Verification--Killing a Process

Use the ps command to be sure that the process has been stopped.

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:
  • System (SYS)
  • Interactive (IA)
  • Real-time (RT)
  • Timesharing (TS)

    · The user-supplied priority ranges from -20 to +20.

    · The priority of a process is inherited from the parent process. This is referred to as the user-mode priority.

    · The system looks up the user-mode priority in the timesharing dispatch parameter table and adds in any nice or priocntl (user-supplied) priority to and ensures a 0-59 range to create a global priority.

· 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 Priority

  1. Become root.

  2. Start a process with a designated priority.


  # priocntl -e -c class -m userlimit -p pri command_name  

In this command,
-eExecutes the command.
-c classSpecifies the class within which to run the process. The default classes are TS (timesharing) or RT (real-time).
-m userlimitSpecifies 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.

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  

· How to Change Scheduling Parameters of a Timeshare Process

  1. Become root.

  2. Change the scheduling parameter of a running timeshare process.


  # priocntl -s -m userlimit [-p userpriority] -i idtype idlist  

In this command,
-sLets you set the upper limit on the user priority range and change the current priority.
-m userlimitSpecifies the maximum amount you can raise or lower your priority, when using the -p option.
-p userpriorityAllows 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.

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  

· How to Change the Class of a Process

  1. (Optional) Become root.


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

  1. Change the class of a process.


  # priocntl -s -c class -i idtype idlist  

In this command,
-sLets you set the upper limit on the user priority range and change the current priority.
-c classSpecifies 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.

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  


Note - If, as root, you change a user process to the real-time class, the user cannot subsequently change the real-time scheduling parameters (using priocntl -s).

· How to Change the Priority of a Process

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_nameIncrease the nice number by four units (the default)
/usr/bin/nice +4 command_nameIncrease the nice number by four units
/usr/bin/nice -10 command_nameIncrease the nice number by ten units
The first command increases the nice number by four units (the default); and the second 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_nameRaises the priority of the command by lowering the nice number
/usr/bin/nice - -10 command_nameRaises 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.