Unix technical interview questions and answers are frequently asked in system administration, DevOps, backend development, and support engineering roles. Unix forms the base for Linux and macOS, so companies expect candidates to understand file permissions, commands, shell scripting, process management, filters, pipes, and environment variables. Interviews in TCS, Infosys, Wipro, Cognizant, Capgemini, and Accenture often include Unix questions during both technical rounds and written tests. This guide explains frequently asked Unix commands and concepts using simple language, making it easy for freshers and experienced candidates to prepare. You can also download Unix interview questions PDFs and practice mock commands for better preparation.
1. Discuss the mount and unmount system calls
Answer: The privileged mount system call is used to attach a file system to a directory of another file system; the unmount system call detaches a file system. When you mount another file system on to your directory, you are essentially splicing one directory tree onto a branch in another directory tree. The first argument to mount call is the mount point, that is , a directory in the current file naming system. The second argument is the file system to mount to that point. When you insert a cdrom to yo
Show Answer
Hide Answer
2. How do you create special files like named pipes and device files?
Answer: 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.
Show Answer
Hide Answer
3. What is a FIFO?
Answer: 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).
Show Answer
Hide Answer
4. Brief about the directory representation in UNIX
Answer: A Unix directory is a file containing a correspondence between filenames and inodes. A directory is a special file that the kernel maintains. Only kernel modifies directories, but processes can read directories. The contents of a directory are a list of filename and inode number pairs. When new directories are created, kernel makes two entries named '.' (refers to the directory itself) and '..' (refers to parent directory).System call for creating directory is mkdir (pathname, mode).
Show Answer
Hide Answer
5. How are devices represented in UNIX?
Answer: All devices are represented by files called special files that are located in/dev directory. Thus, device files and other files are named and accessed in the same way. A 'regular file' is just an ordinary data file in the disk. A 'block special file' represents a device with characteristics similar to a disk (data transfer in terms of blocks). A 'character special file' represents a device with characteristics similar to a keyboard (data transfer is by stream of bits in sequential order
Show Answer
Hide Answer
6. Discuss the mount and unmount system calls
Answer: The privileged mount system call is used to attach a file system to a directory of another file system; the unmount system call detaches a file system. When you mount another file system on to your directory, you are essentially splicing one directory tree onto a branch in another directory tree. The first argument to mount call is the mount point, that is , a directory in the current file naming system. The second argument is the file system to mount to that point. When you insert a cdrom to yo
Show Answer
Hide Answer
7. How does the inode map to data block of a file?
Answer: Inode has 13 block addresses. The first 10 are direct block addresses of the first 10 data blocks in the file. The 11th address points to a one-level index block. The 12th address points to a two-level (double in-direction) index block. The 13th address points to a three-level(triple in-direction)index block. This provides a very large maximum file size with efficient access to large files, but also small files are accessed directly in one disk read.
Show Answer
Hide Answer
8. What is a shell?
Answer: A shell is an interactive user interface to an operating system services that allows an user to enter commands as character strings or through a graphical user interface. The shell converts them to system calls to the OS or forks off a process to execute the command. System call results and other information from the OS are presented to the user through an interactive interface. Commonly used shells are sh,csh,ks etc.
Show Answer
Hide Answer
9. Explain fork() system call.
Answer: The `fork()' used to create a new process from an existing process. The new process is called the child process, and the existing process is called the parent. We can tell which is which by checking the return value from `fork()'. The parent gets the child's pid returned to him, but the child gets 0 returned to him.
Show Answer
Hide Answer
10. How can you get/set an environment variable from a program?
Answer: Getting the value of an environment variable is done by using `getenv()'.
Setting the value of an environment variable is done by using `putenv()'.
Show Answer
Hide Answer
11. How can a parent and child process communicate?
Answer: A parent and child can communicate through any of the normal inter-process communication schemes (pipes, sockets, message queues, shared memory), but also have some special ways to communicate that take advantage of their relationship as a parent and child. One of the most obvious is that the parent can get the exit status of the child.
Show Answer
Hide Answer
12. What is a zombie?
Answer: When a program forks and the child finishes before the parent, the kernel still keeps some of its information about the child in case the parent might need it - for example, the parent may need to check the child's exit status. To be able to get this information, the parent calls `wait()'; In the interval between the child terminating and the parent calling `wait()', the child is said to be a `zombie' (If you do `ps', the child will have a `Z' in its status field to indicate this.)
Show Answer
Hide Answer
13. What are the process states in Unix?
Answer: As a process executes it changes state according to its circumstances. Unix processes have the following states:
Running : The process is either running or it is ready to run .
Waiting : The process is waiting for an event or for a resource.
Stopped : The process has been stopped, usually by receiving a signal.
Zombie : The process is dead but have not been removed from the process table.
Show Answer
Hide Answer
14. What Happens when you execute a command?
Answer: When you enter 'ls' command to look at the contents of your current working directory, UNIX does a series of things to create an environment for ls and the run it: The shell has UNIX perform a fork. This creates a new process that the shell will use to run the ls program. The shell has UNIX perform an exec of the ls program. This replaces the shell program and data with the program and data for ls and then starts running that new program. The ls program is loaded into the new process context, re
Show Answer
Hide Answer
15. What is 'ps' command for?
Answer: The ps command prints the process status for some or all of the running processes. The information given are the process identification number (PID),the amount of time that the process has taken to execute so far etc.
Show Answer
Hide Answer
16. How would you kill a process?
Answer: The kill command takes the PID as one argument; this identifies which process to terminate. The PID of a process can be got using 'ps' command.
Show Answer
Hide Answer
17. What is an advantage of executing a process in background?
Answer: The most common reason to put a process in the background is to allow you to do something else interactively without waiting for the process to complete. At the end of the command you add the special background symbol, &. This symbol tells your shell to execute the given command in the background.
Example: cp *.* ../backup& (cp is for copy)
Show Answer
Hide Answer
18. How do you execute one program from within another?
Answer: The system calls used for low-level process creation are execlp() and execvp(). The execlp call overlays the existing program with the new one , runs that and exits. The original program gets back control only when an error occurs.
execlp(path,file_name,arguments..); //last argument must be NULL
A variant of execlp called execvp is used when the number of arguments is not known in advance.
execvp(path,argument_array); //argument array should be terminated by NULL
Show Answer
Hide Answer
19. What is major difference between the Historic Unix and the new BSD release of Unix System V in terms of Memory Management?
Answer: 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.
Show Answer
Hide Answer
20. What is the main goal of the Memory Management?
Answer: It decides which process should reside in the main memory,
Manages the parts of the virtual address space of a process which is non-core resident,
Monitors the available main memory and periodically write the processes into the swap device to provide more processes fit in the main memory simultaneously.
Show Answer
Hide Answer
21. What scheme does the Kernel in Unix System V follow while choosing a swap device among the multiple swap devices?
Answer: Kernel follows Round Robin scheme choosing a swap device among the multiple swap devices in Unix System V.
Show Answer
Hide Answer
22. What is a Region?
Answer: A Region is a continuous area of a processs address space (such as text, data and stack). The kernel in a ‘Region Table that is local to the process maintains region. Regions are sharable among the process.
Show Answer
Hide Answer
23. What are the events done by the Kernel after a process is being swapped out from the main memory?
Answer:
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.
Show Answer
Hide Answer
24. What do you mean by u-area (user area) or u-block?
Answer: This contains the private data that is manipulated only by the Kernel. This is local to the Process, i.e. each process is allocated a u-area.
Show Answer
Hide Answer
25. What are the entities that are swapped out of the main memory while swapping the process out of the main memory?
Answer: All memory space occupied by the process, processs u-area, and Kernel stack are swapped out, theoretically.Practically, if the processs u-area contains the Address Translation Tables for the process then Kernel implementations do not swap the u-area.
Show Answer
Hide Answer
26. What is Fork swap?
Answer: fork() is a system call to create a child process. When the parent process calls fork() system call, the child process is created and if there is short of memory then the child process is sent to the read-to-run state in the swap device, and return to the user state without swapping the parent process. When the memory will be available the child process will be swapped into the main memory.
Show Answer
Hide Answer
27. What is Expansion swap?
Answer: At the time when any process requires more memory than it is currently allocated, the Kernel performs Expansion swap. To do this Kernel reserves enough space in the swap device. Then the address translation mapping is adjusted for the new virtual address space but the physical memory is not allocated. At last Kernel swaps the process into the assigned space in the swap device. Later when the Kernel swaps the process into the main memory this assigns memory according to the new address translati
Show Answer
Hide Answer
28. How the Swapper works?
Answer: The swapper is the only process that swaps the processes. The Swapper operates only in the Kernel mode and it does not uses System calls instead it uses internal Kernel functions for swapping. It is the archetype of all kernel process.
Show Answer
Hide Answer
29. What are the processes that are not bothered by the swapper? Give Reason.
Answer:
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.
Show Answer
Hide Answer
30. What are the requirements for a swapper to work?
Answer: The swapper works on the highest scheduling priority. Firstly it will look for any sleeping process, if not found then it will look for the ready-to-run process for swapping. But the major requirement for the swapper to work the ready-to-run process must be core-resident for at least 2 seconds before swapping out. And for swapping in the process must have been resided in the swap device for at least 2 seconds. If the requirement is not satisfied then the swapper will go into the wait state on th
Show Answer
Hide Answer
31. What are the criteria for choosing a process for swapping into memory from the swap device?
Answer: 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.
Show Answer
Hide Answer
32. What are the criteria for choosing a process for swapping out of the memory to the swap device?
Answer: The processs memory resident time,
Priority of the process and
The nice value.
Show Answer
Hide Answer
33. What are conditions on which deadlock can occur while swapping the processes?
Answer: 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.
Show Answer
Hide Answer
34. What are conditions for a machine to support Demand Paging?
Answer: Memory architecture must based on Pages,
The machine must support the ‘restartable instructions.
Show Answer
Hide Answer
35. What is ‘the principle of locality?
Answer: Its the nature of the processes that they refer only to the small subset of the total data space of the process. i.e. the process frequently calls the same subroutines or executes the loop instructions.
Show Answer
Hide Answer
36. What is the working set of a process?
Answer: The set of pages that are referred by the process in the last ‘n, references, where ‘n is called the window of the working set of the process.
Show Answer
Hide Answer
37. What is the window of the working set of a process?
Answer: The window of the working set of a process is the total number in which the process had referred the set of pages in the working set of the process.
Show Answer
Hide Answer
38. What is called a page fault?
Answer: Page fault is referred to the situation when the process addresses a page in the working set of the process but the process fails to locate the page in the working set. And on a page fault the kernel updates the working set by reading the page from the secondary device.
Show Answer
Hide Answer
39. What are data structures that are used for Demand Paging?
Answer: Kernel contains 4 data structures for Demand paging. They are,
Page table entries,
Disk block descriptors,
Page frame data table (pfdata),
Swap-use table.
Show Answer
Hide Answer
40. How the Kernel handles the fork() system call in traditional Unix and in the System V Unix, while swapping?
Answer: Kernel in traditional Unix, makes the duplicate copy of the parents address space and attaches it to the childs 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.
Show Answer
Hide Answer
41. Difference between the fork() and vfork() system call?
Answer: During the fork() system call the Kernel makes a copy of the parent processs address space and attaches it to the child process.
But the vfork() system call do not makes any copy of the parents address space, so it is faster than the fork() system call. The child process as a result of the vfork() system call executes exec() system call. The child process from vfork() system call executes in the parents address space (this can overwrite the parents data and stack ) which suspends the paren
Show Answer
Hide Answer
42. What is BSS(Block Started by Symbol)?
Answer: A data representation at the machine level, that has initial values when a program starts and tells about how much space the kernel allocates for the un-initialized data. Kernel initializes it to zero at run-time.
Show Answer
Hide Answer
43. What is Page-Stealer process?
Answer: This is the Kernel process that makes rooms for the incoming pages, by swapping the memory pages that are not the part of the working set of a process. Page-Stealer is created by the Kernel at the system initialization and invokes it throughout the lifetime of the system. Kernel locks a region when a process faults on a page in the region, so that page stealer cannot steal the page, which is being faulted in.
Show Answer
Hide Answer
44. Name two paging states for a page in memory?
Answer:
The two paging states are:
The page is aging and is not yet eligible for swapping,
The page is eligible for swapping but not yet eligible for reassignment to other virtual address space.
Show Answer
Hide Answer
45. What are the phases of swapping a page from the memory?
Answer:
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.
Show Answer
Hide Answer
46. In what way the Fault Handlers and the Interrupt handlers are different?
Answer: 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.
Show Answer
Hide Answer
47. What is validity fault?
Answer:
If a process referring a page in the main memory whose valid bit is not set, it results in validity fault.
The valid bit is not set for those pages:
that are outside the virtual address space of a process,
that are the part of the virtual address space of the process but no physical address is assigned to it.
Show Answer
Hide Answer
48. What does the swapping system do if it identifies the illegal page for swapping?
Answer: If the disk block descriptor does not contain any record of the faulted page, then this causes the attempted memory reference is invalid and the kernel sends a “Segmentation violation” signal to the offending process. This happens when the swapping system identifies any invalid memory reference.
Show Answer
Hide Answer
50. What do you mean by the protection fault?
Answer: Protection fault refers to the process accessing the pages, which do not have the access permission. A process also incur the protection fault when it attempts to write a page whose copy on write bit was set during the fork() system call.
Show Answer
Hide Answer
51. For which kind of fault the page is checked first?
Answer: The page is first checked for the validity fault, as soon as it is found that the page is invalid (valid bit is clear), the validity fault handler returns immediately, and the process incur the validity page fault. Kernel handles the validity fault and the process will incur the protection fault if any one is present.
Show Answer
Hide Answer
52. In what way the protection fault handler concludes?
Answer: After finishing the execution of the fault handler, it sets the modify and protection bits and clears the copy on write bit. It recalculates the process-priority and checks for signals.
Show Answer
Hide Answer
53. How the Kernel handles both the page stealer and the fault handler?
Answer: 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.
Show Answer
Hide Answer