All UNIX Interview Questions
All UNIX Interview Questions
All UNIX Interview Questions
2. What is ‘inode’?
Ans: All UNIX files have its description stored in a structure called ‘inode’. The inode contains info
about the file-size, its location, time of last access, time of last modification, permission and so on.
Directories are also represented as files and have an associated inode. In addition to descriptions about the
file, the inode contains pointers to the data blocks of the file. If the file is large, inode has indirect pointer
to a block of pointers to additional data blocks (this further aggregates for larger files). A block is
typically 8k.
Inode consists of the following fields:
File owner identifier
File type
File access permissions
File access times
Number of links
File size
Location of the file data
7. What is a FIFO?
Ans: FIFO are otherwise called as ‘named pipes’. FIFO (first-in-first-out) is a special file which is said to
be data transient. Once data is read from named pipe, it cannot be read again. Also, data can be read only
in the order written. It is used in interprocess communication where a process writes to one end of the
pipe (producer) and the other reads from the other end (consumer).
8. How do you create special files like named pipes and device files?
Ans: The system call mknod creates special files in the following sequence.
1. kernel assigns new inode,
2. sets the file type to indicate that the file is a pipe, directory or special file,
3. If it is a device file, it makes the other entries like major, minor device numbers.
For example:
If the device is a disk, major device number refers to the disk controller and minor device number is the
disk.
12. Brief about the initial process sequence while the system boots up?
Ans: While booting, special process called the ‘swapper’ or ‘scheduler’ is created with Process-ID 0. The
swapper manages memory allocation for processes and influences CPU allocation. The swapper inturn
creates 3 children:
the process dispatcher, vhand and dbflush with IDs 1,2 and 3 respectively.
This is done by executing the file /etc/init. Process dispatcher gives birth to the shell. Unix keeps track of
all the processes in an internal data structure called the Process Table (listing command is ps -el).
31. What is major difference between the Historic Unix and the new BSD release of Unix System V
in terms of Memory Management?
Ans: Historic Unix uses Swapping – entire process is transferred to the main memory from the swap
device, whereas the Unix System V uses Demand Paging – only the part of the process is moved to the
main memory. Historic Unix uses one Swap Device and Unix System V allow multiple Swap Devices.
34. What scheme does the Kernel in Unix System V follow while choosing a swap device among the
multiple swap devices?
Ans: Kernel follows Round Robin scheme choosing a swap device among the multiple swap devices in
Unix System V.
36. What are the events done by the Kernel after a process is being swapped out from the main
memory?
Ans: When Kernel swaps the process out of the primary memory, it performs the following:
Kernel decrements the Reference Count of each region of the process. If the reference count becomes
zero, swaps the region out of the main memory,Kernel allocates the space for the swapping process in the
swap device,Kernel locks the other swapping process while the current swapping operation is going
on,The Kernel saves the swap address of the region in the region table.
37. Is the Process before and after the swap are the same? Give reason.
Ans: Process before swapping is residing in the primary memory in its original form. The regions (text,
data and stack) may not be occupied fully by the process, there may be few empty slots in any of the
regions and while swapping Kernel do not bother about the empty slots while swapping the process out.
After swapping the process resides in the swap (secondary memory) device. The regions swapped out will
be present but only the occupied region slots but not the empty slots that were present before assigning.
While swapping the process once again into the main memory, the Kernel referring to the Process
Memory Map, it assigns the main memory accordingly taking care of the empty slots in the regions.
39. What are the entities that are swapped out of the main memory while swapping the process out
of the main memory?
Ans: All memory space occupied by the process, process’s u-area, and Kernel stack are swapped out,
theoretically. Practically, if the process’s u-area contains the Address Translation Tables for the process
then Kernel implementations do not swap the u-area.
43. What are the processes that are not bothered by the swapper? Give Reason.
Ans: Zombie process: They do not take any up physical memory.Processes locked in memories that are
updating the region of the process.Kernel swaps only the sleeping processes rather than the ‘ready-to-run’
processes, as they have the higher probability of being scheduled than the Sleeping processes.
45. What are the criteria for choosing a process for swapping into memory from the swap device?
Ans: The resident time of the processes in the swap device, the priority of the processes and the amount
of time the processes had been swapped out.
46. What are the criteria for choosing a process for swapping out of the memory to the swap
device?
Ans: The process’s memory resident time,Priority of the process and the nice value.
48. What are conditions on which deadlock can occur while swapping the processes?
Ans: All processes in the main memory are asleep.All ‘ready-to-run’ processes are swapped out.
There is no space in the swap device for the new incoming process that are swapped out of the main
memory. There is no space in the main memory for the new incoming process.
54. What are data structures that are used for Demand Paging?
Ans: Kernel contains 4 data structures for Demand paging. They are, Page table entries, Disk block
descriptors, Page frame data table (pfdata), Swap-use table.
55. What are the bits that support the demand paging?
Ans: Valid, Reference, Modify, Copy on write, Age. These bits are the part of the page table entry, which
includes physical address of the page and protection bits.
Page address
Age
Copy on write
Modify
Reference
Valid
Protection
56. How the Kernel handles the fork() system call in traditional Unix and in the System V Unix,
while swapping?
Ans: Kernel in traditional Unix, makes the duplicate copy of the parent’s address space and attaches it to
the child’s process, while swapping. Kernel in System V Unix, manipulates the region tables, page table,
and pfdata table entries, by incrementing the reference count of the region table of shared regions.
61. What are the phases of swapping a page from the memory?
Ans: Page stealer finds the page eligible for swapping and places the page number in the list of pages to
be swapped. Kernel copies the page to a swap device when necessary and clears the valid bit in the page
table entry, decrements the pfdata reference count, and places the pfdata table entry at the end of the free
list if its reference count is 0.
63. In what way the Fault Handlers and the Interrupt handlers are different?
Ans: Fault handlers are also an interrupt handler with an exception that the interrupt handlers cannot
sleep. Fault handlers sleep in the context of the process that caused the memory fault. The fault refers to
the running process and no arbitrary processes are put to sleep.
66. What are states that the page can be in, after causing a page fault?
Ans: On a swap device and not in memory, On the free page list in the main memory, In an executable
file, Marked “demand zero”, Marked “demand fill”.
73. How the Kernel handles both the page stealer and the fault handler?
Ans: The page stealer and the fault handler thrash because of the shortage of the memory. If the sum of
the working sets of all processes is greater that the physical memory then the fault handler will usually
sleep because it cannot allocate pages for a process. This results in the reduction of the system throughput
because Kernel spends too much time in overhead, rearranging the memory in the frantic pace.
77. Which are typical system directories below the root directory?
Ans: (1)/bin: contains many programs which will be executed by users (2)/etc : files used by
administrator (3)/dev: hardware devices (4)/lib: system libraries (5)/usr: application software (6)/home:
home directories for different systems.
81. What does the command “ $who | sort –logfile > newfile” do?
Ans: The input from a pipe can be combined with the input from a file . The trick is to use the special
symbol “-“ (a hyphen) for those commands that recognize the hyphen as std input.
In the above command the output from who becomes the std input to sort , meanwhile sort opens the file
logfile, the contents of this file is sorted together with the output of who (rep by the hyphen) and the
sorted output is redirected to the file newfile.
83.Which of the following commands is not a filter man , (b) cat , (c) pg , (d) head
man A filter is a program which can receive a flow of data from std input, process (or filter) it and send
the result to the std output.
84. How is the command “$cat file2 “ different from “$cat >file2 and >> redirection operators ?
Ans: is the output redirection operator when used it overwrites while >> operator appends into the file.
85. Explain the steps that a shell follows while processing a command.
Ans: After the command line is terminated by the key, the shell goes ahead with processing the command
line in one or more passes. The sequence is well defined and assumes the following order.
Parsing: The shell first breaks up the command line into words, using spaces and the delimiters, unless
quoted. All consecutive occurrences of a space or tab are replaced here with a single space.
Variable evaluation: All words preceded by a $ are valuated as variables, unless quoted or escaped.
Command substitution: Any command surrounded by back quotes is executed by the shell which then
replaces the standard output of the command into the command line.
Wild-card interpretation: The shell finally scans the command line for wild-cards (the characters *, ?,
[, ]).
Any word containing a wild-card is replaced by a sorted list of
filenames that match the pattern. The list of these filenames then forms the arguments to the command.
PATH evaluation: It finally looks for the PATH variable to determine the sequence of directories it has to
search in order to hunt for the command.
90. Which command is used to delete all files in the current directory and all its sub-directories?
Ans: rm -r *
100. How does the kernel differentiate device files and ordinary files?
Ans: Kernel checks ‘type’ field in the file’s inode structure.
104. How to terminate a process which is running and the specialty on command kill 0?
Ans: With the help of kill command we can terminate the process.
Syntax: kill pid
Kill 0 – kills all processes in your system except the login shell.