Interacting with Processes


All running processes within Linux are assigned a Process ID (PID). This PID can be used to manage and interact with each process. To locate the PID of a running process, you can use the ps command, as shown in Figure 6.5.

Figure 6.5. The output of the ps command.


By default, the ps command produces a listing of all running processes in the current shell session. Using command-line switches, processes running in other sessions and background daemons can also be viewed. The information displayed for each process includes such things as the user who initiated the process, the Process ID (PID), and the Parent Process ID (PPID).

The first process started on a Linux server is the init process. All other processes are either spawned by init or spawned by a process already started by init. This produces a hierarchical structure for running process. Using the PPID and the PID, the path back to the init daemon can be tracked and is often useful when tracking down rogue or problematic processes.

Another command useful for tracking down troublesome processes is top, shown in Figure 6.6. The top utility can be used to view running processes and also has the advantage of viewing processes based on statistics such as CPU utilization, memory usage, or many other parameters.

Figure 6.6. The output of the top command.


Using top, programs consuming an unusual amount of memory, CPU utilization, or other resources can be quickly identified. When these processes have been identified, several preventative or administrative actions can be taken to resolve potential problems. Normal actions include such things as shutting down and restarting services, but these actions can also include passing a signal directly to the running program.

Signals are an important part of running processes. If a critical event occurs, the kernel communicates that event to the respective process using a signal specific to the event. Using the kill command, these same signals can be manually passed to running programs. The use of signals is similar to passing control characters, such as Ctrl+C, directly to a running process. The syntax for the kill utility is as follows:

 kill [Signal Number or Name] [pid] 

Table 6.4 lists signals commonly used against running processes.

Table 6.4. Common Kill Signals

SIGNAL NUMBER

SIGNAL NAME

DESCRIPTION

1

SIGHUP

Sends a hang-up signal to the specified process. This action causes the process to reinitialize itself thereby reloading its configuration.

2

SIGINT

Sends a keyboard interrupt to the specified process.

9

SIGKILL

Sends a kill signal to the process instructing the kernel to destroy the specified process.

15

SIGTERM

Sends a terminate signal to the process instructing it to shut down or exit.

18

SIGCONT

Sends a continue signal to a process that has been stopped using SIGSTOP.

19

SIGSTOP

Sends a stop signal to the process.


NOTE

For a complete listing of all Linux signals, please use man 7 signal.


The kill command requires the PID of a process in order to function. If you would like to use the name of the process rather than the PID, you can use the killall command. The killall process sends the specified signal to all processes with the specified process name. This is useful when working with several processes, but can also cause signals to be sent to processes unintentionally. Because of this, care should be taken with the killall process.



    NovellR Open Enterprise Server Administrator's Handbook SUSE LINUX Edition
    Novell Open Enterprise Server Administrators Handbook, SUSE LINUX Edition
    ISBN: 067232749X
    EAN: 2147483647
    Year: 2005
    Pages: 178

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net