Unit 4 - Practice Quiz

CSE325

1 What 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

2 Which header file must be included to use the fork() system call?

A. <stdio.h>
B. <sys/types.h>
C. <unistd.h>
D. <stdlib.h>

3 What 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

4 What 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

5 If 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

6 If 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

7 After a fork(), the parent and child processes share which of the following?

A. Stack
B. Heap
C. Open file descriptors
D. Process ID

8 Consider 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

9 Which function is used to replace the current process image with a new process image?

A. fork()
B. exec() family
C. wait()
D. exit()

10 What 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

11 What 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

12 In the function execl(), what must be the last argument passed to the function?

A.
B. -1
C. NULL
D. The environment pointer

13 What 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

14 What 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

15 Which exec function allows you to specify a new environment for the new program?

A. execl()
B. execvp()
C. execv()
D. execle()

16 What 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

17 What 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

18 Which process usually adopts an Orphan process?

A. The Kernel
B. The Shell
C. init (or systemd) - PID 1
D. The Swapper

19 How 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

20 In the output of ps -l, what is the state code typically used for a Zombie process?

A. R
B. S
C. Z
D. D

21 Which system call suspends the execution of the calling process until one of its children terminates?

A. sleep()
B. suspend()
C. wait()
D. stop()

22 The wait() system call requires which header file?

A. <sys/wait.h>
B. <sys/process.h>
C. <sys/child.h>
D. <signal.h>

23 If 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

24 Which macro is used to check if a child process terminated normally?

A. WIFSTOPPED(status)
B. WIFSIGNALED(status)
C. WIFEXITED(status)
D. WNORMAL(status)

25 If WIFEXITED(status) is true, which macro extracts the exit code?

A. WGETEXIT(status)
B. WEXITSTATUS(status)
C. WRETCODE(status)
D. WCHILDSTATUS(status)

26 What is the return value of wait() on success?

A.
B. 1
C. PID of the terminated child
D. PID of the parent

27 What 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

28 Which option allows waitpid() to return immediately if no child has exited?

A. WNOWAIT
B. WSTOPPED
C. WNOHANG
D. WCONTINUED

29 What 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

30 If 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

31 What 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

32 Which signal is sent when you press Ctrl+C in the terminal?

A. SIGKILL
B. SIGSTOP
C. SIGINT
D. SIGQUIT

33 Which system call is used to send a signal to a process?

A. send()
B. signal()
C. kill()
D. raise()

34 Which function is used to register a custom signal handler?

A. kill()
B. signal()
C. alarm()
D. pause()

35 Which of the following signals cannot be caught or ignored?

A. SIGINT
B. SIGTERM
C. SIGSEGV
D. SIGKILL

36 What is the default action for SIGTERM?

A. Ignore the signal
B. Dump core
C. Terminate the process
D. Stop/Suspend the process

37 What signal is generated when a program attempts to access an illegal memory address?

A. SIGFPE
B. SIGILL
C. SIGSEGV
D. SIGBUS

38 The alarm(seconds) system call delivers which signal after the specified time?

A. SIGTIME
B. SIGALRM
C. SIGWAKE
D. SIGUSR1

39 What 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

40 Which signal is used to pause/suspend a process (can be generated by Ctrl+Z)?

A. SIGCONT
B. SIGTSTP
C. SIGINT
D. SIGTERM

41 What 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

42 Which command-line utility sends signals to processes by PID?

A. ps
B. top
C. kill
D. nice

43 In 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

44 If fork() fails, which variable is set to indicate the error?

A. status
B. errno
C. error_code
D. exit_status

45 What 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

46 Which signal corresponds to a floating-point exception (e.g., division by zero)?

A. SIGSEGV
B. SIGABRT
C. SIGFPE
D. SIGPIPE

47 What 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)

48 When 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

49 Consider 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

50 Which 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