Ans: A process is a program which is being executed. There are two mode in process execution: a) user mode and b) kernel mode. Normally, a process executes in the user mode. When a process executes a system call, then the mode of execution changes from user mode to kernel mode.
2. What is scheduling? and type of scheduling?
Ans: On most multitasking systems, only one process can truly active at a time, the system must therefore share its time between the execution of many processes. This time sharing is called Scheduling. There are mainly two types of scheduling.
a) Queuing: This approach for serial or batch jobs like print pooling and request from a server. There are two main ways of giving priority to the jobs in a queue. First Come First Serve(FCFS/FIFO), and Shortest Job First(SJF).
b) Round-robin: In this approach several tasks can co-exist. The scheduler gives a short time-slice to each job, before moving on to the next job, polling each task round and robin. This way, all the tasks advance little by little on a controlled basis.
3. What is Zombie process and Orphan Process?
Ans: On UNIX, a zombie process or defunct process is a process that has completed execution but still has an entry in the process table, allowing the process that started it to read its exit status. Simply, the child process has died but has not yet been reaped.
When a process end, all of the memory and resources associated with it are deallocated so they can be used by other processes, but in this case not because this process entry in the process table. When child ends, parent gets SIGCHLD signal indicating that a child has died, the handler for this signal will typically execute the wait system call, which reads the exit status and remove zombies. If parent ignores the SIGCHLD signal, the zombie will be left in the process table.
If zombie exist for more than a short period of time typically indicate a bug in the parent program. To remove zombies from the system, the SIGCHLD signal can be sent to the parent manually, using kill command. If the parent still refuses, the next step would be remove the parent process. When a process losses its parent, init becomes its new parent, init periodically executes the wait system call to reap any zombies with init as parent.
An Orphan is a process whose parent process has finished or terminated.
4. What is fork(), exec(), wait(), and waitpid()? What is the difference between fork() and vfork()?
Ans: Fork() is used to create a new process. It doesn't take any arguments and returns a process ID. If fork() returns negative number the creation of child process was unsuccessful. A call to fork() returns a zero to newly created child process and the same call to fork() returns a positive number(child process ID) to the parent. Both parent and child process have identical but separate address space.
"init" process is the very first process run upon startup. There are two commands to set the process's priority nice and renice.
exec() functions replaces a current process with another according to the arguments given.
wait() can be used to determine when a child process has completed it's job and finished. wait() causes a parent process to pause until a child process dies or finished. The call returns the PID of the child process for which status information is available.
waitpid() is a system call that can be used to wait fir child process. This call however can be used to wait for specific process to terminate.
The difference between fork() and vfork(): vfork() is a low overhead version of fork(), as fork() involves copying the entire address space of the process and is therefore quite expensive. The basic difference between the two is that when a new process is created with vfork(), the parent process is temporarily suspended, and the child process might borrow the parent's address space. This strange state of affairs continues until the child process either exits, or calls execve(), at which point the parent process continues.
5. What is context switching?
Ans: Switching from one running process to another running process incurs a cost to the system. The values of all the registers must be saved in the present state, the status of all opened files must be recorded and the present position of the program must be recorded. Then the contents of the MMU must be stored for the process. Then all those things must be read in for the next process, so the state of the system is exactly as it was when the scheduler last interrupted the process. This is called context switching.
The state of each process is saved to a data structure in the kernel called process control block(PCB).
6. What are the process states?
Ans: The state of process may be one of the following:
a) New
b) Ready (in line to be executed)
c) Running (active)
d) Waiting (sleeping, suspended)
e) Terminated (defunct)
7. What is the difference between process and Thread?
Ans: Major differences are between process and thread are:
a) Process is Heavy Weight Process, because the context switching between processes is more expensive. It will take more time from one memory location to other memory location. Thread is Light Weight Process since the context switching between threads is less expensive rather than process. Threads are shared their memory location.
b) Threads have direct access to the data segment of its process; processes have their own copy of the data segment of the parent process.
c) Threads can directly communicate with other threads of its process; process must use inter-process communication to communicate with other processes.
d) Threads have almost no overhead; processes have considerable overhead.
8. What is deadlock and possible occurances?
Ans: Deadlock occurs when a number of processes are waiting for an event which can only be caused by another of the waiting process.
These are the essential requirements for a deadlock:
a) Circular Wait: Two or more processes form a circular chain where each process waits for a resource that the next process in the chain holds.
b) Mutual Exclusion: A resource that can't be used by more than one process at a time.
c) No Preemption: The process can't be forced to give up the resources they are holding. Resources can be released only by the explicit action of the process.
d) Hold and Wait: Process already holding a resources may request new resources.
9. What is semaphore?
Ans: A semaphore is a flag which can have a more general value than just true or false. A semaphore is like integer. When you create a semaphore, you can initialize its value to any value to any integer, but after that only operations you are allowed to perform are increment and decrement, but you can't read current value of the semaphore.
When a thread decrements the semaphore, if the result is negative, the thread blocks itself and can't continue until another thread increments the semaphore.
When a thread increments the semaphore, if there are other threads waiting, one of the waiting threads gets unblocked.
10. What is belady's Anomaly?
Ans: It is also called FIFO anomaly because this occurs in case of the FIFO page replacement policy in the OS. Usually, on increasing number of frames allocated to a process's virtual memory, the process execution is faster, because fewer page faults occur. Sometimes revers happens, i.e., the execution time increases even when more frames are allocated to the process.
This does't occur in the LRU(least recently used) scheduling algorithm.
11. What is Translation Look-aside Buffer(TLB)?
Ans: It is a CPU cache that memory management hardware uses to improve virtual address translation speed. A TLB has a fixed number of slots that contain page table entries, which maps virtual addresses to physical addresses.
12. What is busy-waiting?
Ans: The repeated execution of a loop of code while waiting for an event to occur is called busy-waiting. The CPU is not engaged in any real productive activity during this period, and the process does't process towards completion.
13. What is paging? What is page fault? What is demand paging?
Ans: It is one of the memory management scheme which used by operating system to store and retrieve data from secondary storage for use in main memory. In Paging, OS retrieves data from secondary storage in same-size blocks called pages. Main advantage is that it allows the physical address space of a process to be non-contiguous, so this avoids storage and fragmentation problems.
When a program tries to access pages those are not currently mapped to physical address(RAM) is called page fault.
The OS copies a disk pages into physical memory only if the executing process demands them is called Demand paging.
14. What are local and global page replacements?
Ans: Page replacement algorithm can be local or global.
When a process incurs a page fault, local page replacements algorithm selects for replacement some page that belongs to the same process, where as global replacement algorithm is free to select any page in memory.
15. What is cause of thrashing?
Ans: Thrashing is caused by under allocation of the minimum number of pages required by a process, forcing it to continuously page fault. The system can detect thrashing by evaluating the level of CPU utilization as compared to the level of multiprogramming. It can be eliminated by reducing the level of multiprogramming.
To resolve thrashing due to excessive paging, a user can do any of the following:
a) Increase the amount of RAM in the computer (long-term solution)
b) Decrease the number of programs being run on the computer.
c) Replace programs that are memory-heavy with equivalents that use less memory.
16. What is the difference between volatile and non-volatile memory?
Ans: Volatile Memory - They loss the information when not powered. Ex. RAM means temporary memory.
Non-Volatile Memory - They don't loss the information when not powered. Ex: ROM means permanent memory.
17. What is segmentation fault?
Ans: When a program attempts to access a memory location that is not allowed to access, or attempts to access a memory location in a way that is not allowed, for example- attempting to write to a read-only location.
Ex: char c* = "Hello";
*c = 'h';
18. What is fragmentation? What are the types of fragmentation?
Ans: Fragmentation occurs in a dynamic memory allocation system when many of the free blocks are too small to satisfy any request.
There are three types of fragmentation:
a) Internal Fragmentation: The term "internal" refers to the fact that the unusable storage is inside the allocated region but is not being used. Internal fragmentation is the space wasted inside of allocated memory blocks because of restriction on the allowed sizes of allocated blocks. Allocated memory may be slightly larger than requested memory; this size difference is memory internal to a partition, but not being used.
b) External Fragmentation: The term "external" refers to the fact that the unusable storage is outside of the allocated regions. This fragmentation happens when a dynamic memory allocation algorithm allocates some memory and small piece is left over that cannot be effectively used. If too much external fragmentation occurs, the amount of usable memory is drastically reduced. Total memory space exists to satisfy a request, but it is not contiguous. External fragmentation also occurs in file systems as many files of different file sizes are created, change size and are deleted. This effect is even more worse if a file which is divided into many small pieces is deleted, because this leaves similarly small regions of free spaces.
19. What is de-fragmentation?
Ans: De-fragmentation is a process that reduces the amount of fragmentation in file system. It does this by physical organizing the contents of the disk to store the pieces of each file close together and contiguously. It also attempts to create larger regions of free space using compaction. to impede the return of fragmentation.
20. What is compaction?
Ans: Compaction refers to the mechanism of shuffling the memory portions such that all the free portions of the memory can be aligned or merged together in a single large block. To overcome the problem of fragmentation, either internal or external, performs this mechanism frequently. Compaction is possible only if relocation is dynamic and done at run-time. If relocation is static and done at assembly or load-time, compaction is not possible.
No comments:
Post a Comment