Viva Questions and Answers
Viva Questions and Answers
2. Process
Q. What is a process in an operating system?
A process is an instance of a program in execution.
Q. How do you create a new process in Linux?
Use the fork() system call to create a child process.
Q. Explain the difference between process creation using fork() and exec() in Unix.
• fork(): Creates a new process.
• exec(): Replaces the current process image with a new one.
Q. What is a zombie process, and how do you handle it?
A zombie process is a terminated process whose parent has not read its exit status. It can be removed by
the parent using wait().
Q. What is the role of wait() in process management?
wait() suspends the parent process until the child process completes.
3. Signal
Q. What is a signal in Unix/Linux?
A signal is a software interrupt used to communicate with processes.
Q. How do you handle signals in a program?
Using the signal() or sigaction() functions. Example:
signal(SIGINT, handler_function);
Q. Explain the use of the kill command.
kill sends a signal to a process:
kill -9 PID
Q. What are signal sets, and how are they managed?
Signal sets are collections of signals. They can be managed using sigprocmask() and sigset_t.
Q. How would you block or ignore a signal?
Block a signal using sigprocmask() or ignore it using:
signal(SIGINT, SIG_IGN);
4. Semaphore
Q. What is a semaphore, and why is it used?
A semaphore is a synchronization primitive used to manage access to shared resources.
Q. Explain the difference between binary semaphores and counting semaphores.
• Binary Semaphore: Takes values 0 or 1.
• Counting Semaphore: Takes any non-negative integer value.
Q. How are the semget(), semctl(), and semop() functions used in semaphore programming?
• semget(): Create/get a semaphore.
• semctl(): Control semaphore attributes.
• semop(): Perform semaphore operations.
Q. What is a deadlock, and how can semaphores help prevent it?
A deadlock occurs when processes are stuck waiting for each other. Semaphores prevent it by ensuring
resource availability.
5. POSIX Threads
Q. What are POSIX threads, and how are they different from processes?
POSIX threads are lightweight processes that share memory space.
Q. How do you create and join threads in POSIX?
• Create:
pthread_create(&thread_id, NULL, function, arg);
• Join:
pthread_join(thread_id, NULL);
Q. What is the purpose of the pthread_exit() function?
pthread_exit() terminates the calling thread.
Q. How does pthread_join() work, and why is it used?
It waits for a thread to finish and retrieves its return value.
Q. What are thread attributes, and how can you modify them?
Thread attributes define thread behavior. Modify them using pthread_attr_*() functions.
6. Inter-Process Communication (IPC)
Q. What are pipes, and how do they facilitate IPC?
Pipes are unidirectional communication channels between processes.
Q. Explain the difference between named pipes (FIFOs) and unnamed pipes.
• Unnamed Pipes: Exist only during process execution.
• Named Pipes (FIFOs): Persistent and accessible via file paths.
Q. How does message passing work in shared memory IPC?
Processes write to and read from shared memory segments.
Q. What are the functions pipe(), popen(), and pclose() used for?
• pipe(): Creates an unnamed pipe.
• popen()/pclose(): Open/close pipes to external commands.
Q. Discuss the role of semaphores in managing shared memory.
Semaphores synchronize access to shared memory, preventing race conditions.