In this chapter we shall learn about:
1. What is a process?
2. What are different Process State available?
3. Process Control Block [PCB]:
4. How to create a process?
5. Things that are copied from parent process to child process
6. Things where the child process is different from parent process
7. Threads VS Process:
8. wait() and exit() system calls.
9. How to make Inter-Process Communication?
10. Command to list the process in linux?
11. Foreground, Background process?
What is a process?
Accordin to UNIX standards, IEEE Std 1003.1, 2004 Edition, process is “an address space with one or more threads executing within that address space, and the required system resources for those threads.”
What are different Process State available?
Below are different states available in a process:
Process Control Block [PCB]:
PCB is a data structure maintainied by Operating System maintained for every process.
How to create a process?
There are 3 ways to create a process.
1. By using “system()” system call
2. By using “execl” family system calls.
3. By using “fork()” system call.
We shall discuss all the 3 types from next chapters.
Once the process is created using “fork()” system call, the new process created is called as child process. The process that will create a child process is called as parent process.
Below are the things that are copied from parent process to child process:
· real user ID
· real group
· effective user ID
· effective group ID
· process group ID
· terminal group ID
· root directory
· current working directory
· signal handling settings
· file mode creation mask
Below are the things where the child process is different from parent process:
· the child process has a new, unique process ID,
· the child process has a different parent process ID,
· the child process has its own copies of the parent’s file descriptors.
Threads VS Process:
1. Threads are easier to create and destroy.
2. inter-thread communication is cheaper
3. provide faster context switch
4. It is not secure: a thread can write the memory used by another thread
5. User threads are managed and scheduled in userspace
6. User threads can not take full advantage of multithreading
1. They are secure: one process cannot corrupt another process
2. inter-process communication is expensive: need to context switch
wait() and exit() system calls.
wait(): This command is used to make the parent process to wait for a child process to stop or terminate.
It will return the pid of the child or -1 for an error.
exit(): It is used to terminate the process.
How to make Inter-Process Communication?
There are several IPC mechanisms provided by Linux.
Some of them are:
System V shared memory
System V semaphores
System V message queues.
Command to list the process in linux?
Use “ps aux” command to list all the process running in linux.
Foreground, Background process?
A process can be sent into background from the terminal by adding “&”.
For example, if you want to run the command “yum update” command in background, then use “yum update&”.
To get all the applications that are running in background to foreground, then use “fg” command.
To check all the applications running in background, use “bg” command.
You can also use “jobs” command in linux, to get the list of background process.