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 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 . . . |
The /proc File System and Commands
Process tools that are available in the /usr/proc/bin directory display highly detailed information about the processes listed in the /proc directory. (The /proc directory is also known as the process file system (PROCFS).) Images of active processes are stored here by their process ID number.
The process tools are similar to some options of the ps command, except that the output that is provided by the tools is more detailed. In general, the process tools 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 With /proc Tools
You can display detailed, technical information about or control active processes by using some of the process tool commands that are contained in the /usr/proc/bin directory. Table 23-3 lists some of the /proc tools.
If a process becomes trapped in an endless loop, or if it takes too long to execute, you might want to stop (kill) the process. For more information about stopping processes using the pkill command, see Chapter 23, Managing System Processes (Tasks).
The /proc file system is a directory hierarchy that contains additional subdirectories for state information and control functions.
It also provides a watchpoint 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 watchpoint facility, which means that the entire watchpoint process is faster.
The following restrictions have been removed when setting watchpoints by using the dbx debugging tool:
Setting watchpoints on local variables on the stack due to SPARC register windows
Setting watchpoints on multithreaded processes
For more information, see proc(4), core(4), and mdb(1).
Table 23-3 /usr/proc/bin Tools
Process Tool | Description |
---|---|
pcred | Displays process credential information |
pfiles | Reports fstat and fcntl information for open files in a process |
pflags | Prints /proc tracing flags, pending 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).
Note - To avoid typing long command names, add the process tool directory to your PATH variable. Then, you can 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
Obtain the process ID of the process you want to display more information about.
# pgrep process
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.
Display the process information you need.
# /usr/proc/bin/pcommand pid
pcommand
Process tool command that you want to run. Table 23-3 lists these commands.
pid
Indicates the process ID.
Example--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 commands. Next, the identification number for the lpsched process is obtained. Finally, output from three process tool commands is shown.
# PATH=$PATH:/usr/proc/bin # export PATH 1 # pgrep lpsched 2 213 # pwdx 213 3 213: / # ptree 213 4 213 /usr/lib/lpsched # pfiles 213 5 213: /usr/lib/lpsched Current rlimit: 4096 file descriptors 0: S_IFIFO mode:0000 dev:270,0 ino:67 uid:0 gid:0 size:0 O_RDWR 1: S_IFIFO mode:0000 dev:270,0 ino:67 uid:0 gid:0 size:0 O_RDWR 3: S_IFCHR mode:0666 dev:136,0 ino:35882 uid:0 gid:3 rdev:21,0 O_WRONLY FD_CLOEXEC 4: S_IFDOOR mode:0444 dev:275,0 ino:18526 uid:0 gid:0 size:0 O_RDONLY|O_LARGEFILE FD_CLOEXEC door to nscd[208] 5: S_IFREG mode:0664 dev:136,0 ino:64648 uid:71 gid:8 size:0 O_WRONLY |