Saturday, July 4, 2020

System Calls in Linux : fork() and exec()

Hi,

In this post I am going to discuss about the system call that the process makes to the Kernel.

There are two system calls available in Linux namely...

1. fork()
2. exec()

System Call fork()
When ever the user wants to execute a program, the kernel of Linux does the operation in the following way...

Consider a user wants to list the contents of a directory, normally 'ls' is the program which lists the contents of the directory but the process that does execute the process 'ls' is shell, which can be either a simple sh 'sh' or bourne again shell 'bash'... here the shell is forked first and then the process 'ls' is given to the shell process.

Normally, in Linux when ever a child process is executed by the parent process, the parent process should be forked first and the child process would be supplied to it.

Forking is a process to make a exact copy of a process

System Call exec()
When the exec() system call is made, the kernel would just execute the program, normally the syntax of this system call would be exec() or exec(<program in action>)

The below diagram would help you to understand the system call discussed in a simplified way...


Well that is it, hope you had good time.

Thanks.



Thursday, July 2, 2020

Process Management in Linux : Time Slicing and Context Switching

Hi,

In this post I am going to discuss about the Context Switching and Time Slicing in Linux.

As we all know that Linux operating system classifies the memory into two space namely....

1. User Space
2. Kernel Space

The user space is where the user processes run and kernel space is where the kernel processes run, the purpose of kernel in Linux operating system is that it acts as a resource manager.

In Linux, the kernel treats everything as resource including the hardware, this abstraction would make the kernel to switch the resources between two modes namely

1. User Mode
2. Kernel Mode

One of the restrictions is Linux is that no User Process can access the hard ware resource directly without the knowledge of kernel, in order to gain access to the hardware resources, the kernel must set the hardware resource to user mode i.e for the User Process to gain access over the hardware resource and start using them.

For our discussion, let us take Central Processing Unit(CPU).

In Linux the central processing unit is a resource from the kernel's point of view so that it can switch the modes of CPU between user to kernel and vice versa.

Whenever the CPU is at the User Mode, it means the User Process is utilizing the CPU.

What the hell is Time Slicing?

Time Slicing is a process in which the kernel decides how long a user process could make use of the CPU.

What is Context Switching?

Context Switching is a process of giving up the control over CPU by a User Process to an other User Process to gain control over the CPU for a specified time slice.

Context Switching is the time duration where the Linux kernel comes in and does the house keeping(Memory, State of the Process etc...) work of the User Process that is about to give away the control of the CPU and prepares the memory for the next User Process that is about to gain the control of the CPU.

The following Image would let you understand in a comprehensive way...


Well that is it, hope you had great time reading.

Thanks.


How to change the root password in linux when it is forgotten/to change

This blog is all about changing the root password of the Linux system when it is forgotten or to reset the password...   Let's get it ...