Linux Unleashed, Third Edition:Processes
-->
Previous
Table of Contents
Next
Chapter 34Processes
by Tim Parker
In This Chapter
What you need to know about processes
Using the ps command
Using kill
Everything that runs on a Linux system is a processevery user task, every system daemoneverything is a process. Knowing how to manage the processes running on your Linux system is an important (indeed even critical) aspect of system administration. This chapter looks at processes in some detail. In the course of discussing processes, we wont bother with the mechanics behind how processes are allocated or how the Linux kernel manages to time-slice all the processes to run a multitasking operating system. Instead, well look at the nitty-gritty aspects of process control that you need in order to keep your system running smoothly.
You may come across the terms process and job used when dealing with multitasking operating systems. For most purposes, both terms are correct. However, a job is usually a process started by a shell (and may involve many processes), while a process is a single entity that is executing. To be correct, well use the term process throughout.
What You Need to Know About Processes
A formal definition of a process is that it is a single program running in its own virtual address space. This means that everything running under Linux is a process. This is compared to a job, which may involve several commands executing in a series. Alternatively, a single command line issued at the shell prompt may involve more than one process, especially when pipes or redirection is involved. For example, the following command will start three processes, one for each command:
nroff -man ps.1 | grep kill | more
Types of Processes
There are several types of processes involved with the Linux operating system. Each has its own special features and attributes. The processes involved with Linux are as follows:
Interactive processes: A process initiated from (and controlled by) a shell. Interactive processes may be in foreground or background.
Batch processes: Processes that are not associated with a terminal but are submitted to a queue to be executed sequentially.
Daemon processes: Processes usually initiated when Linux boots and that run in the background until required.
Using the ps Command
The easiest method of finding out which processes are running on your system is to use the ps (process status) command. The ps command has a number of options and arguments, although most system administrators use only a couple of common command line formats. We can start by looking at the basic usage of the ps command, and then examine some of the useful options.
The ps command is available to all system users, as well as root, although the output changes a little depending on whether you are logged in as root when you issue the command.
When you are logged in as a normal system user (in other words, any login but root) and issue the ps command on the command line by itself, it displays information about every process you are running. For example, you might see the following output when you issue the command:
$ ps
PID TTY STAT TIME COMMAND
41 v01 S 0:00 -bash
134 v01 R 0:00 ps
ps Command Output
The output of the ps command is always organized in columns. The first column is labeled PID, which means Process ID number. Every process on the system has to have a unique identifier so Linux can tell which processes it is working with. Linux handles processes by assigning a unique number to each process, called the process ID number (or PID). PIDs start at zero when the system is booted and increment by one for each process run, up to some system-determined number (such as 65,564) at which point it starts numbering from zero again, ignoring those that are still active. Usually, the lowest number processes are the system kernel and daemons, which start when Linux boots and remain active as long as Linux is running. When you are working with processes (such as terminating them), you must use the PID.
The TTY column in the ps command output shows you which terminal the process was started from. If you are logged in as a user, this will usually be your terminal or console window. If you are running on multiple console windows, you will see all the processes you started in every window displayed.
The STAT column in the ps command output shows you the current status of the process. The two most common entries in the status column are S for sleeping and R for running. A running process is one that is currently executing on the CPU. A sleeping process is one that is not currently active. Processes may switch between sleeping and running many times every second.
The TIME column shows the total amount of system (CPU) time used by the process so far. These numbers tend to be very small for most processes because they require only a short time to complete. The numbers under the TIME column are a total of the CPU time, not the amount of time the process has been alive.
Finally, the COMMAND column contains the name of the command line you are running. This is usually the command line you used, although some commands start up other processes. These are called child processes, and they show up in the ps output as if you had entered them as commands.
Login Shells
As a general convention, a login shell has a hyphen placed before its name (such as -bash in the preceding output) to help you distinguish the startup shell from any shells you may have started afterward. Any other shells that appear in the output do not have the hyphen in front of the name, as the following example shows:
$ ps
PID TTY STAT TIME COMMAND
46 v01 S 0:01 -bash
75 v01 S 0:00 pdksh
96 v01 R 0:00 bash
123 v01 R 0:00 ps
This output shows that the users startup shell is bash (PID 46), and that he or she started up the Korn shell (pdksh, PID 75) and another Bourne shell (bash, PID 96) afterward.
Notice in the preceding outputs that the command that actually shows you the process status, ps, appears on the output because it was running when you issued the command. The ps command always appears on the output.
Previous
Table of Contents
Next
Wyszukiwarka
Podobne podstrony:
609 611README (609)Nuestro Circulo 609 VUGAR VASHIMOV609 613Vzduchovka Slavia 612612,17,artykulMotyw ojczyzny w literaturze staropolskiej I literatury ~612MAXa0 i 612611 612PIONEER PDR 609Ch18 pg593 612609 (2)więcej podobnych podstron