Linux Process Introduction:
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:
1. New
2. Running
3. Waiting
4. Ready
5. Terminated
Process Control Block [PCB]:
PCB is a data structure maintainied by Operating System maintained for every 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,
· the time left until an alarm clock signal is set to zero in the child.
Threads VS Process:
Threads:
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
Processes
1. They are secure: one process cannot corrupt another process
2. inter-process communication is expensive: need to context switch
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.
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:
signals
pipes
semaphores
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.