0% found this document useful (0 votes)
30 views5 pages

Viva Questions and Answers

The document provides a comprehensive overview of Unix/Linux operating system concepts, including shell scripting, process management, signals, semaphores, POSIX threads, and inter-process communication (IPC). It covers key topics such as creating and executing shell scripts, managing processes and signals, understanding semaphores for synchronization, and using threads for concurrent execution. Additionally, it explains the differences between various types of devices, user management, and the significance of run levels.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views5 pages

Viva Questions and Answers

The document provides a comprehensive overview of Unix/Linux operating system concepts, including shell scripting, process management, signals, semaphores, POSIX threads, and inter-process communication (IPC). It covers key topics such as creating and executing shell scripts, managing processes and signals, understanding semaphores for synchronization, and using threads for concurrent execution. Additionally, it explains the differences between various types of devices, user management, and the significance of run levels.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Viva Questions and Answers: (Operating System)

1. Managing Unix/Linux Operating System


Q. What is a shell script, and how do you create one?
A shell script is a file containing a series of commands that can be executed by the shell. To create one:
1. Open a text editor (e.g., vi or nano).
2. Write the commands in the file.
3. Save the file with a .sh extension.
Q. How can you make a shell script executable?
Use the chmod command:
chmod +x script_name.sh
Q. Explain the role of variables in shell scripts with examples.
Variables store data that can be used and manipulated within the script. Example:
name="John"
echo "Hello, $name"
Q. What are control structures in shell scripting? Provide examples.
Control structures allow decision-making and iteration. Examples:
• If-else:
if [ $num -gt 10 ]; then
echo "Number is greater than 10"
else
echo "Number is less than or equal to 10"
fi
• For loop:
for i in 1 2 3; do
echo $i
done
Q. How do you define and use functions in shell scripting?
Functions are defined using the following syntax:
function_name() {
commands
}
Example:
greet() {
echo "Hello, $1"
}
greet "World"
Q. What is the difference between raw and block devices?
• Raw Devices: Accessed directly without buffering, used in databases.
• Block Devices: Accessed via buffered I/O, used for file systems.
Q. How is the swap space managed in Linux?
Swap space is used as virtual memory to supplement RAM. Commands to manage:
• Check usage: swapon -s
• Enable swap: swapon /dev/swap_partition
Q. Explain the process of mounting and unmounting file systems.
• Mounting: Attach a file system using mount:
mount /dev/sda1 /mnt
• Unmounting: Detach a file system using umount:
umount /mnt
Q. What is an inode, and why is it important in a file system?
An inode is a data structure that stores metadata about a file, such as its size, permissions, and location on
disk.
Q. Discuss the significance of run levels in Unix/Linux.
Run levels define the state of the system:
• 0: Halt
• 1: Single-user mode
• 5: Multi-user mode with GUI
• 6: Reboot
Q. How do you add and remove user accounts in Linux?
• Add user:
useradd username
• Remove user:
userdel username
Q. Explain the difference between groups and user groups in Linux.
• Groups: Collection of users for managing permissions.
• User Groups: Groups created automatically for individual users.

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.

You might also like