The two fundamental concepts in a Linux operating system are processes and time slice. A process is an instance of a program that is being executed by the computer’s operating system. When we say that two computers are communicating with each other, we mean that two processes, one running on each computer, are in communication with each other. The only way a new process can be created by the Linux system is by issuing the fork() system call. We need to understand here that system calls are the entry points through which an active process can obtain the services from the kernel.
Linux operates on the principle of time slice – every single process is given a little bit of time for its execution. If the process execution is not completed, then it will be put in a suspended mode till it gets its time slice and after that it continues its execution. The switch between different processes happens so fast that an end user will never be able to visualise it.
Let us explain the time slice concept with an example – assume that there are two processes and Linux gives each a time slice of two seconds. When two seconds elapse for the first process, it is moved into the swap area. Now the second process starts to execute. Once its two seconds are over, it will be moved into the swap area. The first process will be reloaded and its execution begins. This switch happens every two seconds until one of the processes finishes.
Let us see how we can create new processes by using fork() system call:
printf(“Hello, this is a test programn”);
The above is a simple example with only two lines of code (Fig 1 above). After compiling and executing the above program, we can see that the statement ‘Hello, this is a test program’ will be displayed twice (Fig 2 below).