Sunday, June 23, 2013

Processes in UNIX

I would like to continue my mini tutorials in Unix/Linux. I will focus on the topic of Processes in this post. I will try to compile as many tutorials as possible in the next few posts on Unix covering basics and will move to advanced topics. This would be a learning experience for me as well.

Coming to the context..

Process is an instance of a program in execution. Its also called task or job. For example the command who would display all the users currently logged into Unix. Here the execution of the program who is a process. The actual program resides on the secondary memory (such as hard disk) while the process will be executed in the RAM. (In some cases memory may be allocated from secondary memory as well which is known as virtual memory).

Some key aspects of processes:

  • Process is “born” when it starts execution and is said to “die” when it completes execution
  • Kernel takes care of process management
  • Process communicates with other process through system calls
  • Process is created by the “fork” system call.

 

There must be some process which starts ‘fork’ as well. This is called parent process and the new process created is called child process. Each process is associated with “process_id”.  The First Process which gets created is Process 0 (called Parent process as told before), when the system boots up. After this process is ‘Forked’ for a child process, process 0 becomes ‘swapper’ process. This process is part of the kernel and will be used for scheduling other processes.

The child process is called ‘Process 1’ which is considered as ancestor of every process in UNIX and is called the ‘init’ process.

After the system gets logged in, the Kernel creates the SHELL process. Hence Shell is also a process and is associated with PID. To know PID type the below command:

echo $$

For example, in the below command:

ls –l | more

The parent process is the shell. ls-l is executed first and the output is fed to more which displays output one page at a time. Hence ls-l and more are two child processes here.

To know about the process states, issue the below command

image

    PID 1520 is the process id for the SHELL. PPIS is the parent id which is the process 1 (init). We can see the command ‘more’ has PPID 1520 (therefore a child process for the SHELL). We can also see the command ps –f itself. This presents a clear picture of the processes.  

In the next session we will discuss about how exactly is the process created,where fork comes into picture and so on.                           

Technorati Tags: ,,,

No comments:

Post a Comment