In this article we will create, monitor different types of linux processes and illustrate IPC process communication applications using practical examples, code snippets. Subscribe here to earn a certificate from our online courses listed here. Your low cost subscription will enable complete access to all technical articles, online tests, projects to clear all online course requirements.
Learn linux process, creating a process, states of linux process, zombie process, creating process using fork system call, getting process ID(PID) and group info using system calls.
What is a linux process?
A process is an active program i.e. a program that is under execution.
Process is more than the program code as it includes the program counter, process stack, registers, program code etc. Compared to this, the program code is only the text section.
A process is a program or a command executed by user to perform specific task. Hence task and process are terms that Linux uses interchangeably
Each process in linux is given a unique process ID called a PID.
Linux is a multitasking system which means several processes/tasks run at the same time
Processes communicate between then using Inter process communication methods such as signals, pipes, semaphores and also the System V IPC mechanisms of shared memory, semaphores and message queues.
Along with normal processes, Linux supports real time processes. Real time processes have to react very quickly to external events (switch, buttons etc...) and they are treated differently from normal user processes by the scheduler.
Each process in linux is represented by a task_struct data structure
Creating a Linux process
Let's write the following small program square.c and create an executable SQUARE for it.
printf("Enter a number\n");
while(num < 10)
printf("Square of your number:%d\n",num * num);
$ gcc square.c -o SQUARE
Enter a number
Square of your number:9
Enter a number
Square of your number:25
Enter a number
Let's open another console and execute ps -aux command to observe the process we have created.
$ ps -aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.6 26936 5940 ? Ss 01:46 0:02 /sbin/init splash
pi 2063 0.0 0.0 1812 328 pts/0 S+ 05:09 0:00 ./SQUARE
pi 2115 0.0 0.3 7736 2868 pts/1 R+ 05:13 0:00 ps -aux
When we executed the ps -aux command we got all processes information detail. I have intentionally removed the other processes and kept few lines for your observation
Observation I: Init is the first process created in linux startup that is given PID as 1 and root is the user for it.
Observation II: Our program executable SQUARE is also now a process and we see it is running with pi as the user.
Observation III: The ps -aux command we executed to observe the running processes in Linux is also treated as another process and pi is the user for it.
States of process, Zombie process
To Read Full Article
You need to subscribe & logged in
Want to contribute or ask a new article? Write and upload your article info here