1What is the primary purpose of the fork() system call in Unix-like operating systems?
A.To execute a new program in the same process
B.To create a new process that is a duplicate of the calling process
C.To terminate the current process
D.To synchronize two processes
Correct Answer: To create a new process that is a duplicate of the calling process
Explanation:fork() is used to create a new process, which is an exact copy of the calling process, except for the returned value and the process ID.
Incorrect! Try again.
2Which header file must be included to use the fork() system call?
A.<stdio.h>
B.<sys/types.h>
C.<unistd.h>
D.<stdlib.h>
Correct Answer: <unistd.h>
Explanation:The fork() system call is defined in the <unistd.h> header file, which provides access to the POSIX operating system API.
Incorrect! Try again.
3What does fork() return to the child process upon success?
A.The Process ID (PID) of the parent
B.The Process ID (PID) of the child
C.
D.-1
Correct Answer:
Explanation:On success, fork() returns 0 to the child process and the child's PID to the parent process.
Incorrect! Try again.
4What does fork() return to the parent process upon success?
A.
B.The Process ID (PID) of the newly created child process
C.The Process ID (PID) of the parent itself
D.-1
Correct Answer: The Process ID (PID) of the newly created child process
Explanation:To distinguish between the two processes, fork() returns the positive PID of the child to the parent.
Incorrect! Try again.
5If fork() returns -1, what does it indicate?
A.The child process was created successfully
B.The process is now an orphan
C.The process creation failed
D.The process is now a zombie
Correct Answer: The process creation failed
Explanation:A return value of -1 indicates that the system failed to create a new process, usually due to resource limits.
Incorrect! Try again.
6If the following code is executed, how many times is "Hello" printed?
c
fork();
fork();
printf("Hello\n");
A.2
B.3
C.4
D.8
Correct Answer: 4
Explanation:The number of processes created is , where is the number of fork() calls. Here , so processes are running, each printing "Hello".
Incorrect! Try again.
7After a fork(), the parent and child processes share which of the following?
A.Stack
B.Heap
C.Open file descriptors
D.Process ID
Correct Answer: Open file descriptors
Explanation:Memory segments (stack, heap) are copied (or marked copy-on-write), and PIDs are unique. However, the child inherits copies of the parent's open file descriptors.
Incorrect! Try again.
8Consider the code below. What is the relationship between variable x in the parent and child?
c
int x = 10;
if (fork() == 0) {
x = 20;
}
A.Changing x in the child changes x in the parent
B.The parent and child have separate copies of x
C.The variable x becomes shared memory automatically
D.The program will segfault
Correct Answer: The parent and child have separate copies of x
Explanation:Processes have separate address spaces. Modifying a variable in the child process does not affect the variable in the parent process.
Incorrect! Try again.
9Which function is used to replace the current process image with a new process image?
A.fork()
B.exec() family
C.wait()
D.exit()
Correct Answer: exec() family
Explanation:The exec() family of functions replaces the current process image with a new process image specified by the path and arguments.
Incorrect! Try again.
10What happens to the Process ID (PID) after a successful exec() call?
A.A new PID is assigned
B.The PID remains the same
C.The PID becomes 0
D.The PID becomes equal to the parent's PID
Correct Answer: The PID remains the same
Explanation:exec() replaces the code and data of the current process but preserves the Process ID (PID) and the file descriptor table (unless FD_CLOEXEC is set).
Incorrect! Try again.
11What is the return value of an exec() function if it is successful?
A.
B.The PID of the process
C.It does not return
D.-1
Correct Answer: It does not return
Explanation:If exec() is successful, the current program code is completely replaced. Therefore, there is no code left in the original program to return to.
Incorrect! Try again.
12In the function execl(), what must be the last argument passed to the function?
A.
B.-1
C.NULL
D.The environment pointer
Correct Answer: NULL
Explanation:The list of arguments in execl() must be terminated by a NULL pointer to indicate the end of the argument list.
Incorrect! Try again.
13What is the difference between execl() and execv()?
A.execl() takes an array of arguments, execv() takes a list
B.execl() takes a list of arguments, execv() takes an array (vector)
C.execl() searches the PATH, execv() does not
D.execl() requires environment variables, execv() does not
Correct Answer: execl() takes a list of arguments, execv() takes an array (vector)
Explanation:The 'l' stands for list (arguments passed individually), and the 'v' stands for vector (arguments passed as an array of strings).
Incorrect! Try again.
14What does the suffix 'p' indicate in execvp()?
A.It takes a pointer as an argument
B.It uses the PATH environment variable to find the file
C.It creates a pipe
D.It is for parallel execution
Correct Answer: It uses the PATH environment variable to find the file
Explanation:Functions with 'p' (like execvp, execlp) search for the executable in the directories specified by the PATH environment variable.
Incorrect! Try again.
15Which exec function allows you to specify a new environment for the new program?
A.execl()
B.execvp()
C.execv()
D.execle()
Correct Answer: execle()
Explanation:The 'e' suffix indicates that the function takes an additional argument (an array of character pointers) to specify the environment for the new process.
Incorrect! Try again.
16What is a Zombie process?
A.A process that is running indefinitely
B.A process that has finished execution but whose parent has not yet waited for it
C.A process whose parent has terminated
D.A process blocked on I/O
Correct Answer: A process that has finished execution but whose parent has not yet waited for it
Explanation:A zombie holds an entry in the process table (store exit status) until the parent reads it via wait(). It uses no memory or CPU.
Incorrect! Try again.
17What is an Orphan process?
A.A process that has terminated
B.A process created by init
C.A process whose parent has terminated while it is still running
D.A process that refuses to terminate
Correct Answer: A process whose parent has terminated while it is still running
Explanation:An orphan is a running process whose parent terminates. It is typically adopted by the init process (PID 1) or systemd.
Incorrect! Try again.
18Which process usually adopts an Orphan process?
A.The Kernel
B.The Shell
C.init (or systemd) - PID 1
D.The Swapper
Correct Answer: init (or systemd) - PID 1
Explanation:When a parent dies, the operating system reparents the orphan child to the init process (PID 1), which periodically waits for children to clean them up.
Incorrect! Try again.
19How can a Zombie process be removed from the system process table?
A.By sending SIGKILL to the zombie
B.By the parent process calling wait() or waitpid()
C.By terminating the child process again
D.It cannot be removed until reboot
Correct Answer: By the parent process calling wait() or waitpid()
Explanation:Zombies are already dead; you cannot kill them. The parent must acknowledge their termination by calling wait() to release the process table entry.
Incorrect! Try again.
20In the output of ps -l, what is the state code typically used for a Zombie process?
A.R
B.S
C.Z
D.D
Correct Answer: Z
Explanation:The state code 'Z' represents a 'Zombie' or 'defunct' process.
Incorrect! Try again.
21Which system call suspends the execution of the calling process until one of its children terminates?
A.sleep()
B.suspend()
C.wait()
D.stop()
Correct Answer: wait()
Explanation:wait() blocks the parent process until a child process changes state (usually termination).
Incorrect! Try again.
22The wait() system call requires which header file?
A.<sys/wait.h>
B.<sys/process.h>
C.<sys/child.h>
D.<signal.h>
Correct Answer: <sys/wait.h>
Explanation:The definitions for wait(), waitpid(), and associated macros are found in <sys/wait.h>.
Incorrect! Try again.
23If wait(&status) is called, what does the integer pointed to by status contain?
A.The PID of the child
B.The execution time of the child
C.Information about how the child terminated (exit code/signal)
D.The memory address of the child
Correct Answer: Information about how the child terminated (exit code/signal)
Explanation:The status integer encodes the exit status or the signal that caused the termination. Macros like WEXITSTATUS are used to extract the value.
Incorrect! Try again.
24Which macro is used to check if a child process terminated normally?
A.WIFSTOPPED(status)
B.WIFSIGNALED(status)
C.WIFEXITED(status)
D.WNORMAL(status)
Correct Answer: WIFEXITED(status)
Explanation:WIFEXITED(status) returns true if the child terminated normally (e.g., by calling exit() or returning from main).
Incorrect! Try again.
25If WIFEXITED(status) is true, which macro extracts the exit code?
A.WGETEXIT(status)
B.WEXITSTATUS(status)
C.WRETCODE(status)
D.WCHILDSTATUS(status)
Correct Answer: WEXITSTATUS(status)
Explanation:WEXITSTATUS(status) returns the least significant 8 bits of the status argument that the child passed to exit().
Incorrect! Try again.
26What is the return value of wait() on success?
A.
B.1
C.PID of the terminated child
D.PID of the parent
Correct Answer: PID of the terminated child
Explanation:wait() returns the Process ID of the terminated child so the parent knows which child finished.
Incorrect! Try again.
27What is the difference between wait() and waitpid()?
A.wait() waits for any child, waitpid() can wait for a specific child
B.wait() is non-blocking, waitpid() is blocking
C.wait() works on threads, waitpid() works on processes
D.There is no difference
Correct Answer: wait() waits for any child, waitpid() can wait for a specific child
Explanation:waitpid() allows specifying a PID to wait for. It also supports options like WNOHANG for non-blocking waits.
Incorrect! Try again.
28Which option allows waitpid() to return immediately if no child has exited?
A.WNOWAIT
B.WSTOPPED
C.WNOHANG
D.WCONTINUED
Correct Answer: WNOHANG
Explanation:WNOHANG causes waitpid to return immediately with 0 if no child has exited, preventing the parent from blocking.
Incorrect! Try again.
29What does the following code snippet do?
c
if (fork() != 0) {
wait(NULL);
}
A.The child waits for the parent
B.The parent waits for the child to finish
C.Both processes wait for input
D.It creates a zombie process
Correct Answer: The parent waits for the child to finish
Explanation:fork() != 0 is true in the parent. The parent then calls wait(NULL), blocking until the child terminates.
Incorrect! Try again.
30If a parent process does not call wait() and terminates before the child, what happens to the child?
A.It becomes a Zombie
B.It becomes an Orphan
C.It is killed immediately
D.It enters a deadlock
Correct Answer: It becomes an Orphan
Explanation:If the parent dies first, the child is orphaned and adopted by init.
Incorrect! Try again.
31What is a Signal in an operating system?
A.A variable shared between threads
B.A hardware interrupt
C.A software interrupt/notification sent to a process
D.A command to start a process
Correct Answer: A software interrupt/notification sent to a process
Explanation:Signals are software interrupts used to notify a process that a specific event has occurred (e.g., termination request, division by zero).
Incorrect! Try again.
32Which signal is sent when you press Ctrl+C in the terminal?
A.SIGKILL
B.SIGSTOP
C.SIGINT
D.SIGQUIT
Correct Answer: SIGINT
Explanation:SIGINT (Signal Interrupt) is generated by the terminal driver when the user types the interrupt character (usually Ctrl+C).
Incorrect! Try again.
33Which system call is used to send a signal to a process?
A.send()
B.signal()
C.kill()
D.raise()
Correct Answer: kill()
Explanation:Despite its name, the kill() system call is used to send any signal to a process, not just to kill it.
Incorrect! Try again.
34Which function is used to register a custom signal handler?
A.kill()
B.signal()
C.alarm()
D.pause()
Correct Answer: signal()
Explanation:The signal() function (or the more modern sigaction()) is used to associate a specific function (handler) with a signal.
Incorrect! Try again.
35Which of the following signals cannot be caught or ignored?
A.SIGINT
B.SIGTERM
C.SIGSEGV
D.SIGKILL
Correct Answer: SIGKILL
Explanation:SIGKILL (9) and SIGSTOP cannot be caught, blocked, or ignored. They ensure the OS can always control/terminate processes.
Incorrect! Try again.
36What is the default action for SIGTERM?
A.Ignore the signal
B.Dump core
C.Terminate the process
D.Stop/Suspend the process
Correct Answer: Terminate the process
Explanation:SIGTERM requests process termination. Unlike SIGKILL, it can be caught to perform cleanup before exiting.
Incorrect! Try again.
37What signal is generated when a program attempts to access an illegal memory address?
A.SIGFPE
B.SIGILL
C.SIGSEGV
D.SIGBUS
Correct Answer: SIGSEGV
Explanation:SIGSEGV (Segmentation Violation) is sent when a process makes an invalid virtual memory reference (segmentation fault).
Incorrect! Try again.
38The alarm(seconds) system call delivers which signal after the specified time?
A.SIGTIME
B.SIGALRM
C.SIGWAKE
D.SIGUSR1
Correct Answer: SIGALRM
Explanation:alarm() arranges for a SIGALRM signal to be delivered to the calling process in the specified number of seconds.
Incorrect! Try again.
39What happens if a process receives a signal for which it has set SIG_IGN as the handler?
A.The process terminates
B.The signal is ignored
C.The default handler is executed
D.The process stops
Correct Answer: The signal is ignored
Explanation:SIG_IGN stands for Ignore Signal. The kernel discards the signal without interrupting the process.
Incorrect! Try again.
40Which signal is used to pause/suspend a process (can be generated by Ctrl+Z)?
A.SIGCONT
B.SIGTSTP
C.SIGINT
D.SIGTERM
Correct Answer: SIGTSTP
Explanation:SIGTSTP (Terminal Stop) is generated by the terminal driver when Ctrl+Z is pressed. It stops the process.
Incorrect! Try again.
41What happens to a child process's memory space immediately after fork() (assuming Copy-On-Write)?
A.It is physically duplicated immediately
B.It shares the same physical frames as the parent, marked read-only
C.It is empty
D.It is shared with write permissions
Correct Answer: It shares the same physical frames as the parent, marked read-only
Explanation:Modern OSs use Copy-On-Write (COW). Parent and child share pages read-only. A physical copy is made only when one of them tries to write.
Incorrect! Try again.
42Which command-line utility sends signals to processes by PID?
A.ps
B.top
C.kill
D.nice
Correct Answer: kill
Explanation:The kill command in the shell invokes the kill() system call to send signals (default is SIGTERM) to processes.
Incorrect! Try again.
43In the context of execv(path, argv), what is argv[0] by convention?
A.The first command line argument
B.The file name of the program being executed
C.The environment variables
D.The parent PID
Correct Answer: The file name of the program being executed
Explanation:By convention, the first argument in the argument vector (argv[0]) is the name of the program itself.
Incorrect! Try again.
44If fork() fails, which variable is set to indicate the error?
A.status
B.errno
C.error_code
D.exit_status
Correct Answer: errno
Explanation:Like most system calls, on failure fork() returns -1 and sets the global variable errno to indicate the specific error.
Incorrect! Try again.
45What is the result of kill(pid, 0)?
A.It kills the process immediately
B.It sends SIGTERM
C.It does not send a signal but checks if the process exists
D.It stops the process
Correct Answer: It does not send a signal but checks if the process exists
Explanation:Sending signal 0 is a special case used to check validity of the PID and permission to send signals without actually sending one.
Incorrect! Try again.
46Which signal corresponds to a floating-point exception (e.g., division by zero)?
A.SIGSEGV
B.SIGABRT
C.SIGFPE
D.SIGPIPE
Correct Answer: SIGFPE
Explanation:SIGFPE stands for Floating-Point Exception, triggered by arithmetic errors like division by zero or overflow.
Incorrect! Try again.
47What happens if you execute kill -9 <PID>?
A.Sends SIGTERM (Polite kill)
B.Sends SIGKILL (Force kill)
C.Sends SIGINT (Interrupt)
D.Sends SIGHUP (Hangup)
Correct Answer: Sends SIGKILL (Force kill)
Explanation:The -9 flag specifies signal number 9, which is SIGKILL. This forces the process to terminate immediately.
Incorrect! Try again.
48When a process handles a signal using a custom handler, where does execution resume after the handler finishes?
A.The process terminates
B.At the beginning of the main function
C.At the point where it was interrupted
D.It waits for the next signal
Correct Answer: At the point where it was interrupted
Explanation:After the signal handler returns, normal execution resumes at the exact instruction where the process was interrupted.
Incorrect! Try again.
49Consider the code: execl("/bin/ls", "ls", "-l", NULL); printf("Done"); Will "Done" be printed?
A.Yes, always
B.No, if execl succeeds
C.Yes, but before ls output
D.Only if ls fails
Correct Answer: No, if execl succeeds
Explanation:If execl succeeds, the process image is replaced. The line printf("Done"); no longer exists in memory and is never executed.
Incorrect! Try again.
50Which system call is used to wait for a state change in a child process?
A.waitid()
B.waitpid()
C.wait()
D.All of the above
Correct Answer: All of the above
Explanation:wait(), waitpid(), and waitid() are all variations of system calls used to wait for state changes in child processes.
Incorrect! Try again.
Give Feedback
Help us improve by sharing your thoughts or reporting issues.