Welcome to this spoken tutorial on Working with Linux Processes.
I am using Ubuntu 10.04.
We assume that you know how to get started with the Linux operating system and have some basic idea about commands.
If you are interested, it is available through another spoken tutorial on the following website. http://spoken-tutorial.org
Also note that Linux is case sensitive. All the commands used in this tutorial are in lower case unless otherwise mentioned.
To understand what a process is, let me give you a brief explanation.
Anything that is running in Linux is a process.
The shell that is running and taking our commands is a process.
The commands that we type on the terminal are processes when they are running.
The video in which you are seeing this tutorial is a process.
The browser running in which you have opened the spoken tutorial website is a process.
Shell scripts that are running are processes and so on.
A process can be defined as a program which is being executed i.e. which is running.
Processes are much like us. They are born, they die. They have parent and children.
Let us first learn about the shell process.
The shell process is started by the Linux kernel as soon as we login to the system.
At this point it would suffice to know that the 'Linux kernel' is the core of the Linux operating system.
It consists of the most essential components that makes Linux run. The shell creates or gives birth to all the other user command processes.
Let us open a terminal.
We can see the command prompt on the terminal in the form of a dollar sign.
This is the job of the shell process.
Now, let us type any command say “date” and press Enter.
As soon as we do this the shell process will create a process called 'date'.
Now, since the shell process has given birth to the 'date' process, we can say that the 'shell process' is the parent of the 'date process' and the 'date process' is the child of the 'shell process'.
Once 'date' process has shown the system date and time, it will die.
A shell can also give birth to another shell process. Giving birth to a process or creating a process is also called spawning a process.
To spawn another shell process, simply go to the terminal and type “sh” and press Enter.
We would see a new prompt appearing in the terminal. Now our original shell, let us call it 'shell 1', has given birth to a child shell or 'sub shell', let us call it 'shell 2'.
Now you may run a command in the new command prompt as well. Let us run 'ls' command in this new command prompt.
Now at the command prompt, type “ls” and press Enter. We can see a list of files and directories.
Now a new process named 'ls' is created.
Here, 'shell 2' is the parent of 'ls', while 'shell 1' is the grandparent of 'ls'. 'ls' is the child of 'shell 2', while 'shell 2' itself is the child of 'shell 1'.
To kill 'shell 2', simply type at the new prompt “exit” and press Enter.
This will kill 'shell 2' and we will get back our original command prompt.
Continuing our analogy between us and processes, we know that each of us have some attributes that identify us. Those attributes can be our name, parents' name , date of birth, PAN card no. etc.
Similarly, processes also have attributes like PID(Process ID), PPID(Parent Process ID), Start time, etc.
Most of these attributes are maintained by the kernel in a process table.
Each process is uniquely identified by a unique integer called the PID. PID is allotted by the kernel when the process is born.
The PID of the parent process that spawned a new process say 'P1' is called the PPID of 'P1' process.
To see the PID of the current shell, at the prompt type “echo space dollar dollar” and press Enter.
A number would be shown. This is the PID of the current shell.
The one command that we would use a lot while talking about processes is the ps command.
ps or process status is a command which displays the processes running in the system.
Let us see what happens if we run this command without any options.
Now, at the command prompt type “ps” and press Enter.
This way we would normally see the list of all the processes owned by the user running the program.
You can see the name of the process under CMD heading.
Other than this you can a see the PID, TTY or the console at which the process is running ,the TIME
that is the total processor time that has been used since the process started.
On my machine it displays two processes.
One is bash, the shell process we are using. The other is the 'ps' process itself.
The other important thing to note here is that the PID of the shell process is same as that shown by the 'echo space dollar dollar' command.
If we spawn a sub-shell , let us see what happens. At the terminal type “sh” and press Enter.
Now, in the new prompt that appears on the new line, type “ps” and press Enter.
Now we can see 3 processes in the list . The process 'sh' has been added.
Here again notice that the PID of the bash process is same as that before.
'ps' comes with many options as we would see next. First option that we would see displays more attributes for the processes listed.
Now type at the prompt “ps space minus f” and press Enter. This again will list three processes as in the previous case.
Bash, sh and ps -f.
The only difference is, now more attributes are listed.
UID gives the user name of the user who has started the process. Also it shows the PPID that is the PID of the parent process that created the process.
For example, see that 'bash' process is the parent of 'sh' process , so the PID of bash is same as the PPID of 'sh' process.
Similarly since 'sh' process is the parent of 'ps' process, the PID of 'sh' process is the same as the PPID of the 'ps -f' process.
'C' stands for processor utilization. Currently, this is the integer value of the percent usage of the processor over the lifetime of the process.
It will be displayed as 0 in this case as the usage is negligible.
The 'STIME' field gives the time at which the process started, the rest we have already seen while running 'ps'.
Processes are of two types : First one is User processes. Those are started by the users.
For example 'ps' or for that reason most commands that we run on the terminal.
Second one is system processes. Those processes are started by the system often during system startup or user login.
Example of system process can be 'bash'.
Sometimes we may want to see all the processes - both system processes as well as user processes.
Then we use the 'minus e' or the 'minus capital A' option.
Go to the terminal and type at the prompt “ps space minus e” and press Enter.
We can see a large list of processes.
To get a multipage display just type at the prompt
“ps space minus e space vertical bar space more” and press Enter.
As we have seen before, 'more' will cause only as many processes to be listed as can fit in one window.
As we press Enter, we scroll through the list of processes.
The first process in this list is interesting. It is called the 'init' process.
It is the process from which almost all other processes are spawned.
It has a PID of 1.
To come back to the prompt press 'q'.
So, in this tutorial, we have learned about process, shell process, spawning of process, process attributes and different types of processes.
We also learned the use of 'ps' command. This brings me to the end of this tutorial.
Spoken Tutorials is a part of the Talk to a Teacher project, supported by the National Mission on Education through ICT, MHRD, Government of India.
More information on the same is available at the following link http://spoken-tutorial.org/NMEICT-Intro.
This script has been contributed by ----------------------(name of the translator) and this is -----------------------(name of the recorder) from --------------------------(name of the place)signing off. Thanks for joining.