Managing System Information, Processes, and Performance in Oracle® Solaris 11.2

Exit Print View

Updated: September 2014
 
 

Commands for Managing System Processes

The following table describes the commands for managing system processes.

Table 2-1  Commands for Managing Processes
Command
Description
Man Page
ps, pgrep, prstat, pkill
Check the status of active processes on a system, and also displays detailed information about the processes.
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.
pargs, preap
Assists with process debugging.
dispadmin
Lists default process scheduling policies.
priocntl
Assigns processes to a priority class and manages process priorities.
nice
Changes the priority of a timesharing process.
psrset
Binds specific process groups to a group of processors rather than to just a single processor.

Using the ps Command

The ps command enables you to check the status of active processes on a system, and also 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:

  • Current status of the process

  • Process ID

  • Parent process ID

  • User ID

  • Scheduling class

  • Priority

  • Address of the process

  • Memory used

  • CPU time used

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

UID

The effective user ID of the process's owner.

PID

The process ID.

PPID

The parent process 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 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 in the PROCFS by their process ID number.

Table 2-2  Process Commands (/proc)
Process Command
Description
pcred
Displays process credential information
pfiles
Reports fstat and fcntl information for open files in a process
pflags
Displays /proc tracing flags, pending signals and held signals, and other status information
pldd
Lists the dynamic libraries that are linked into a process
pmap
Displays the address space map of each process
psig
Lists the signal actions and handlers of each process
prun
Starts each process
pstack
Displays a hex+symbolic stack trace for each lightweight process 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 the proc (1) man page.

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.

    The process commands do the following:

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

  • Provide control over processes by allowing users to stop or resume them

Managing Processes by Using Process Commands (/proc)

You can display detailed technical information about processes or control active processes by using some of the process commands. Table 2–2 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 2, Managing System Processes.

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 the xwatchpoint facility, which means that the entire xwatchpoint process is faster.

    The following restrictions no longer apply when you set xwatchpoints by using the dbx debugging tool:

  • Setting xwatchpoints on local variables on the stack due to SPARC based system register windows.

  • Setting xwatchpoints on multithreaded processes.

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

How to List Processes

  • 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 2-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 18:04:04 ?           0:15 sched
    root     5     0   0 18:04:03 ?           0:05 zpool-rpool
    root     1     0   0 18:04:05 ?           0:00 /sbin/init
    root     2     0   0 18:04:05 ?           0:00 pageout
    root     3     0   0 18:04:05 ?           2:52 fsflush
    root     6     0   0 18:04:05 ?           0:02 vmtasks
  daemon   739     1   0 19:03:58 ?           0:00 /usr/lib/nfs/nfs4cbd
    root     9     1   0 18:04:06 ?           0:14 /lib/svc/bin/svc.startd
    root    11     1   0 18:04:06 ?           0:45 /lib/svc/bin/svc.configd
  daemon   559     1   0 18:04:49 ?           0:00 /usr/sbin/rpcbind
  netcfg    47     1   0 18:04:19 ?           0:01 /lib/inet/netcfgd
   dladm    44     1   0 18:04:17 ?           0:00 /sbin/dlmgmtd
  netadm    51     1   0 18:04:22 ?           0:01 /lib/inet/ipmgmtd
    root   372   338   0 18:04:43 ?           0:00 /usr/lib/hal/hald-addon-cpufreq
    root    67     1   0 18:04:30 ?           0:02 /lib/inet/in.mpathd
    root   141     1   0 18:04:38 ?           0:00 /usr/lib/pfexecd
  netadm    89     1   0 18:04:31 ?           0:03 /lib/inet/nwamd
    root   602     1   0 18:04:50 ?           0:02 /usr/lib/inet/inetd start
    root   131     1   0 18:04:35 ?           0:01 /sbin/dhcpagent
  daemon   119     1   0 18:04:33 ?           0:00 /lib/crypto/kcfd
    root   333     1   0 18:04:41 ?           0:07 /usr/lib/hal/hald --daemon=yes
    root   370   338   0 18:04:43 ?           0:00 /usr/lib/hal/hald-addon-network-discovery
    root   159     1   0 18:04:39 ?           0:00 /usr/lib/sysevent/syseventd
    root   236     1   0 18:04:40 ?           0:00 /usr/lib/ldoms/drd
    root   535     1   0 18:04:46 ?           0:09 /usr/sbin/nscd
    root   305     1   0 18:04:40 ?           0:00 /usr/lib/zones/zonestatd
    root   326     1   0 18:04:41 ?           0:03 /usr/lib/devfsadm/devfsadmd
    root   314     1   0 18:04:40 ?           0:00 /usr/lib/dbus-daemon --system
    .
		.
		.

How to Display Information About Processes

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

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

  2. Display the process information.
    # /usr/bin/pcommand PID
    pcommand

    The process command that you want to run. Table 2–2 lists and describes these commands.

    PID

    Identifies the process ID.

Example 2-2  Displaying Information About Processes

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

# pgrep cron Obtains the process ID for the cron process
4780
# pwdx 4780 Displays the current working directory for the cron process
4780:   /var/spool/cron/atjobs
# ptree 4780 Displays the process tree that contains the cron process
4780  /usr/sbin/cron
# pfiles 4780 Displays fstat and fcntl information
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

How to Control Processes

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

    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

    The process command that you want to run. Table 2–2 lists and describes these commands.

    PID

    Identifies the process ID.

  3. Verify the process status.
    # ps -ef | grep PID

Terminating a Process (pkill, kill)

You might need to stop (kill) a process that is in an endless loop, or stop a large job before it is completed. You can kill any process that you own. The system administrator 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) , pkill (1) , and kill (1) man pages.

How to Terminate a Process (pkill)

  1. ()To terminate the process of another user, assume the root role.
  2. Obtain the process ID for the process that you want to terminate.
    $ pgrep process

    For example:

    $ pgrep netscape
    587
    566

    The process ID is displayed in the output.


    Note -  To obtain information about processes on a Sun Raysystem, use the following commands:

    To list all user processes:

    # ps -fu user

    To locate a specific process owned by a user:

    # ps -fu user | grep process

  3. Terminate the process.
    $ pkill [signal] PID
    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 because data might be lost.

    PID

    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. If the process does not terminate after a few minutes, use 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.

How to Terminate a Process (kill)

  1. ()To terminate the process of another user, assume the root role.
  2. Obtain the process ID of the process that you want to terminate.
    # ps -fu user

    where user is the owner of the process.

    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 because 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.
    $ ps

    The process you terminated should no longer be listed in the output of the ps 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 that are 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. When you become an administrator, you can examine any process.

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

Example 2-3  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 all 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