Saturday, May 5, 2012
Posted by Raghu Kumar on 10:01 AM
What is the difference between kernel mode and user mode? What is a system call?
The difference between kernel mode and user mode is similar to that of a Administrator and user logins of the computer.
The administrator can change the settings etc and thus has all the required permissions, whereas the user can only use as per the settings done by the administrator. This distinguishing is done to see that the user does not misuse or by chance corrupt the settings.
Similarly the operating systems runs in the kernel mode(administrator) and the user mode (user).
Since in kernel mode, programs have direct access to all the hardware and the devices, the operating system provides a mechanism for the user, so that the user can access the devices using them. The mechanism are the system calls.
All the applications run in the user mode and whenever a user needs to utilize any of the devices he needs to use system calls. Then the control is transferred from the user to the kernel and the specified read or write of data is performed.
Thus removing the possibility of the user to corrupt the devices or the settings unknowingly.
What is the difference between a thread and a process?
When a binary is executed it runs as a process in the system. Every process gets its time of execution from the process depending on the system specific algorithm.
Suppose if there are two processes then each of them might get 5 seconds each and after 5 seconds process one is removed and process two is replaced and executed and then again after 5 seconds the second process is removed and process one is replaced with the previous values and this continues.
Let us assume that a process is given 10 sec of time and in that if we span/create a thread then the thread is created in the same process address space and the time allocated for the parent process is shared between the parent and the created child thread equally i.e. 5 seconds each and if another thread is created the time is divided between the two and they use the common process address space. So finally there are only two processes in the system and three threads in a process.
If on the other hand if a process is created during the execution then a new process is created and is given a separate process time. So if there were two processes and each process was given 5 seconds each then after a new process is created there are three process each with 5 seconds of time. Each process will have its own address space.
For performance improvement if a parent spawns a process then both the parent and child share the data section of the parent for calculation as long as either of the process parent or child do not change the data in that section.
Whenever any one of them say parent changes the data, before the data is being changed the data is copied to both the processes address space and data is changed only in the parent process and not in the child. Similarly if child changes the data then the data is copied from the parents address space and then changed in the child’s address space. This is called copy on write mechanism.
What is the difference between a character device and a block device drivers?
Character device is a device from which data is read or written as a stream of bytes i.e as a stream of bytes.
Examples : Serial ports, Consoles etc
Block device as the name suggests is a device from which data is read or written as blocks, or chunk of data at once. Normally a block would be of 4096 bytes.
Examples: Hard drives on the system.
The performance of a block driver is important as it involves movement of data from the physical memory to the virtual memory (hard disk) whenever there is a process switch. Where as performance of a character driver does not affect the performance of the system much.