SCSA10-1 Objective 5.2 - Solaris control system processes, view and clear processes, schedule processes

The usage of four command line utilities comprise this objective: ps, kill, at, and crontab. Piece of cake.

Control system processes by viewing the processes, clearing frozen processes, and scheduling automatic one-time and recurring execution of commands using the command line.

Viewing processes

A running program in Solaris is called a process, is associated with a 16-bit process id number (pid), a user and a group. Viewing running processes is accomplished with the ps command. While ps has quite a few options, the most commonly used options are -e and -f. With no options, ps will show minimal information about running processes owned by the user running ps. The -e option shows everyone’s processes. The -f option adds more information about the processes.

# ps -ef
UID PID PPID C STIME TTY TIME CMD
root 0 0 0 Dec 13 ? 0:08 sched
root 1 0 0 Dec 13 ? 0:21 /sbin/init
root 2 0 0 Dec 13 ? 0:00 pageout
root 3 0 1 Dec 13 ? 563:20 fsflush
...

The column UID shows the user owning the process and PID shows the process id. PPID is the “parent process id” or the PID of the process that spawned the process (for example, running ps from a Korn shell makes the Korn shell the parent of ps). C is obsolete (and ignorable). STIME is the starting time (and ultimately date) of the process. TTY is the terminal associated with the process or ? if there is none. TIME shows the cumulative CPU time the process has used and CMD is the command itself complete with options.

The ps command is most useful in collaboration with grep which allows searching for a string. Several examples:

All processes owned by root: ps -ef | grep root
All processes associated with terminal pts/3: ps -ef | grep pts/3
All Apache web server processes: ps -ef | grep https

Killing processes

Given a PID of a nonresponsive process that you want to terminate, you can use the kill command. The kill command actually just sends a “signal” to the process, the meaning of which depends on the signal and sometimes the process. Signals have a numeric value and an associated name. The default signal sent is 15 or SIGTERM which signals a process to try to gracefully exit (close open files before terminating, for example). This should always be the first kill attempted on a questionable process. The command to nicely terminate process 1234 is kill 1234

If SIGTERM doesn’t do the job, SIGKILL (9) will do the job, but will do so uncleanly. No effort will be made to preserve application data. To end process 1234 which failed to end when SIGTERM was sent to it, use kill -9 1234 or kill -s KILL 1234

Scheduling one-time execution of commands

If you want something to run once at a later time, the at command will do the trick. It has some flashy options, but the basic use is sufficient for the exam. To run the (imaginary) command dostuff at 5:30 pm today, the at command is:

at 5:30pm
dostuff
^D

In this use of the at command, it expects one or more commands from the standard input which it will read until and end of file is encountered (the CTRL-D at the end). There are numerous options for setting the time. Here are several examples from the at man page:

at 0815am Jan 24
at 8 :15amjan24
at now "+ 1day"
at 5 pm FRIday

scheduling automatic recurring execution of commands

The cron system in Solaris accomplishes this objective and is documented at Tech-Recipes.

Comments are closed.