Chapter 23 Managing System Processes (Tasks)
This chapter describes the procedures for managing system
processes. This is a list of the step-by-step instructions in this chapter.
Commands for Managing System Processes (Overview)
The following table describes the commands for managing system processes.
Table 23–1 Commands for Managing Processes
|
Command
|
Man Page
|
Description
|
|
ps, pgrep, prstat
|
ps(1), pgrep(1), and prstat(1M)
|
Checks the status of active processes
on a system, as well as displays detailed information about the processes
|
|
dispadmin
|
dispadmin(1M)
|
Lists default scheduling policies
|
|
priocntl
|
priocntl(1)
|
Assigns processes to a priority class and manages process priorities
|
|
nice
|
nice(1)
|
Changes the priority of a timesharing process
|
|
psrset
|
psrset(1M)
|
Binds specific process groups to a group of processors rather than to just
a single processor
|
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 “Working With the Management Console (Tasks)”
in System Administration Guide: Basic Administration.
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.
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 ps(1).
Table 23–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 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.
|
How to List Processes
You can use the ps command to list all the processes
on a system.
|
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—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
You can display detailed information about the processes listed in the /proc directory by using 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.
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:
-
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 Process Commands
You can display detailed, technical information about or control active
processes by using some of the process commands. Table 23–3
lists some of the /proc commands.
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.
The /proc file system 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:
For more information, see proc(4), core(4), and mdb(1).
Table 23–3
/proc Process Commands
|
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 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).
How to Display Information About Processes
-
Obtain the process ID of the process you want to display more information
about.
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.
|
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.
# pgrep lpsched 1
213
# pwdx 213 2
213: /
# ptree 213 3
213 /usr/lib/lpsched
# pfiles 213 4
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
|
-
Obtains the process identification number for lpsched
-
Displays the current working directory for lpsched
-
Displays the process tree that containslpsched
-
Displays fstat and fcntl
information
How to Control Processes
-
Obtain the process ID of the process you want to control.
process is the name of the process you want
to control.
The process identification number is in the first column of the output.
-
Use the appropriate process command to control the process.
|
pcommand
|
Process command you want to run. Table 23–3 lists these commands.
|
|
pid
|
Identifies the process ID.
|
-
Verify the process status.
Example—Controlling Processes
The following example shows how to use process tools to stop and restart dtpad.
# pgrep dtpad 1
2921
# pstop 2921 2
# prun 2921 3
|
-
Obtains the process identification number for dtpad
-
Stops the dtpad process
-
Restarts the dtpad process
Killing a Process (pkill)
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, and
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 might crash
the system.
For more information, see pgrep(1).
How to Kill a Process
-
(Optional) To kill a process that belongs to another user, become superuser.
-
Obtain the of the process ID of the process you want to stop.
process is the name of the process you want
to display more information about.
The process identification number is displayed in the first column of
the output.
-
Stop the process.
|
-9
|
Ensures that the process terminates
promptly.
|
|
pid
|
Process ID to stop.
|
-
Verify that the process has been stopped.
Managing Process Class Information
The following list identifies the process scheduling classes that can
be configured on your system, and the user priority range for the timesharing
class. The possible process scheduling classes are as follows:
-
Fair share (FSS)
-
Fixed (FX)
-
System (SYS)
-
Interactive (IA)
-
Real-time (RT)
-
Timesharing (TS)
-
The user-supplied priority ranges from -60 to +60.
-
The priority of a process is inherited from the parent process.
This priority 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 and ensures a 0–59 range
to create a global priority.
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.
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).
How to Display Basic Information About Process Classes (priocntl)
You can display process scheduling classes and priority ranges with
the priocntl -l command.
Example—Getting 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
|
How to Display the Global Priority of a Process
You can display the global priority of a process by using the ps command.
The global priority is listed under the PRI column.
Example—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 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 (priocntl)
-
Become superuser.
-
Start a process with a designated priority.
# priocntl -e -c class -m userlimit -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), or FX (fixed priority).
|
|
-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 -60 to +60.
|
-
Verify the process status.
# ps -ecl | grep command-name
|
Example—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
|
How to Change Scheduling Parameters of a Timesharing Process (priocntl)
-
Become superuser.
-
Change the scheduling parameters of a running timesharing 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 you
use 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 or processes. The idtype specifies the type of ID, such as pid
or UID. Use idlist to identify
a list of pids or UIDs.
|
-
Verify the process status.
Example—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 -t 500 -p 20 myprog
# ps -ecl | grep myprog
|
How to Change the Class of a Process (priocntl)
-
(Optional) Become superuser.
Note –
You must be superuser or working in a real-time shell to change
a process from, or to, a real-time process.
-
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 or processes. The idtype specifies the type of ID, such as pid
or UID. Use idlist to identify
a list of pids or UIDs.
|
-
Verify the process status.
Example—Changing the Class of a Process (priocntl)
The following example shows how to change 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 by
using the priocntl -s command.
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, and is determined by several factors, including its 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. But 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 between 0 and +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.
How to Change the Priority of a Process (nice)
Note –
This section describes the syntax of the /usr/bin/nice command and not the C-shell nice built-in command.
For information about the C-shell nice command, see csh(1).
-
Determine whether you want to lower the priority of a command as a user
or raise or lower the priority of a command as superuser and select one of
the following:
-
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
|
-
As superuser, 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
|
For more information, see nice(1).
Troubleshooting Problems With System Processes
Here are some tips on obvious problems you might find:
-
Look for several identical jobs that are owned by the same
user. This problem might occur because of a running script that starts a lot
of background jobs without waiting for any of the jobs to finish.
-
Look for a process that has accumulated a large amount of
CPU time. You can identify this problem by checking the TIME
field in the ps output. Possibly, the process is in an
endless loop.
-
Look for a process that is running with a priority that is
too high. Use the ps -c command to see the CLS field, which displays the scheduling class of each process. A process
executing as a real-time (RT) process can monopolize the
CPU. Or, look for a timesharing (TS) process with a high nice number. A user with superuser privileges might have increased
the priority of a process. The system administrator can lower the priority
by using the nice command.
-
Look for a runaway process. A runaway process
progressively uses more and more CPU time. You can identify this problem by
looking at the time when the process started (STIME) and
by watching the cumulation of CPU time (TIME) for a while.