Unit 4: Process Management & Signals - Practice Quiz

CSE325 — Operating Systems Laboratory 50 Questions
0 Correct 0 Wrong 50 Left
0/50

1 Which system call is used to create a new process in Unix-like operating systems?

A. fork()
B. spawn()
C. create()
D. new()

2 What is the return value of fork() in the child process?

A. The Process ID (PID) of the child
B. The Process ID (PID) of the parent
C. -1
D. 0

3 If fork() fails to create a new process, what value does it return?

A. -1
B. 1
C. 0
D. NULL

4 When fork() is executed, the child process gets a copy of the parent's address space. How is this memory copying typically optimized in modern OSs?

A. Shared Memory Reference
B. Copy-on-Write (COW)
C. Deep Copy
D. Segmentation Fault

5 Consider the following code snippet. How many times will "Hello" be printed?

fork();
fork();
printf("Hello\n");

A. 3
B. 8
C. 2
D. 4

6 If a C program executes fork(); three times sequentially (fork(); fork(); fork();), how many new processes are created?

A. 7
B. 8
C. 4
D. 3

7 Which header file is primarily required to use the fork() system call?

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

8 What happens to the Process ID (PID) after a successful exec() call?

A. The PID becomes the Parent's PID
B. The PID remains the same
C. The PID becomes 0
D. A new PID is assigned

9 Which of the following exec functions expects the arguments as a NULL-terminated array of pointers?

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

10 What is the primary difference between execl() and execlp()?

A. execl() creates a new process, execlp() does not.
B. execlp() uses the PATH environment variable to find the executable, execl() requires the full path.
C. execl() takes an environment array, execlp() does not.
D. execlp() is used for python scripts only.

11 If exec() is successful, what value does it return to the calling function?

A. 0
B. The PID of the new program
C. It does not return
D. 1

12 In the command execl("/bin/ls", "ls", "-l", NULL);, why is "ls" passed as the second argument?

A. By convention, argv[0] is the name of the program itself.
B. It is the return type specifier.
C. It is a typo.
D. It is required to specify the path twice.

13 Which system call is used to replace the current process memory space with a new program?

A. wait()
B. signal()
C. fork()
D. exec()

14 What is a Zombie process?

A. A system daemon running in the background.
B. A process that has finished execution but whose parent has not yet called wait().
C. A process that is executing an infinite loop.
D. A process whose parent has terminated.

15 What is an Orphan process?

A. A process that refuses to terminate.
B. A process created by the init system.
C. A process that has finished execution but is still in the process table.
D. A process whose parent process has terminated while the child is still running.

16 Which process usually adopts an orphan process in a classic Unix system?

A. The zombie process
B. The swapper process
C. The init process (PID 1)
D. The shell

17 How can a system administrator remove a Zombie process from the process table?

A. Send the SIGKILL signal to the zombie's parent.
B. Send the SIGKILL signal to the zombie.
C. Restart the compiler.
D. Use the clean command.

18 Which state does a process enter immediately after the exit() system call if the parent is sleeping?

A. Ready
B. Running
C. Orphan
D. Zombie

19 What is the primary purpose of the wait() system call?

A. To block the calling process until one of its children terminates.
B. To prevent the creation of orphan processes.
C. To pause the execution of the process for a specific time.
D. To wait for I/O operations to complete.

20 What is the parameter passed to the wait(int *status) system call used for?

A. To store the exit status of the terminated child.
B. To set the waiting time duration.
C. To send a signal to the child.
D. To specify which child PID to wait for.

21 What does wait() return on success?

A. The PID of the terminated child
B. 1
C. 0
D. The exit status of the child

22 Which macro is used to check if a child process terminated normally (i.e., by calling exit or returning from main)?

A. WIFSIGNALED(status)
B. WEXITSTATUS(status)
C. WIFEXITED(status)
D. WTERMSIG(status)

23 If WIFEXITED(status) is true, which macro extracts the actual exit code (0-255) returned by the child?

A. WEXITCODE(status)
B. WEXITSTATUS(status)
C. WRETURN(status)
D. WGETEXIT(status)

24 What is the difference between wait() and waitpid()?

A. wait() is blocking, waitpid() is always non-blocking.
B. wait() waits for any child, waitpid() can wait for a specific child.
C. wait() is used for threads, waitpid() for processes.
D. There is no difference.

25 Which option flag can be used with waitpid() to make it return immediately if no child has exited (non-blocking)?

A. WUNTRACED
B. WNOHANG
C. WNOWAIT
D. WBLOCK

26 What happens if a parent process calls wait() but has no child processes?

A. It crashes with a segmentation fault.
B. It creates a new child.
C. It returns immediately with -1.
D. It waits indefinitely.

27 What is a Signal in an operating system?

A. A software interrupt or notification sent to a process.
B. A synchronization primitive for threads.
C. A hardware interrupt.
D. A network packet.

28 Which signal is sent to a process when the user presses Ctrl+C in the terminal?

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

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

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

30 Which system call is used to send a signal to a specific process?

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

31 What does the signal() system call do?

A. Sends a signal to a process.
B. Registers a function to handle a specific signal.
C. Waits for a signal.
D. Creates a new signal type.

32 What is the default action for SIGSEGV (Segmentation Fault)?

A. Restart the process
B. Stop the process
C. Terminate the process and dump core
D. Ignore the signal

33 Which signal is sent to a parent process when a child process terminates?

A. SIGUSR1
B. SIGCHLD
C. SIGTERM
D. SIGPARENT

34 What does the handler SIG_IGN do when passed to the signal() function?

A. Restores the default action.
B. Terminates the process.
C. Logs the signal to a file.
D. Ignores the signal.

35 Which header file defines standard signal names like SIGINT and SIGKILL?

A. <signal.h>
B. <unistd.h>
C. <stdlib.h>
D. <sys/wait.h>

36 In the kill(pid_t pid, int sig) system call, if pid is 0, to whom is the signal sent?

A. All processes in the same process group as the sender.
B. Only the init process.
C. No process.
D. All processes in the system.

37 What does the command kill -9 <pid> do in a shell?

A. Sends SIGKILL (9) to the process.
B. Pauses the process.
C. Sends SIGINT (2) to the process.
D. Sends SIGTERM (15) to the process.

38 Which function is a more robust and modern alternative to signal() for handling signals?

A. sigwait()
B. sigprocmask()
C. sigaction()
D. sigqueue()

39 What is the effect of alarm(unsigned int seconds) system call?

A. It sleeps the process for the specified seconds.
B. It arranges for a SIGALRM signal to be delivered after the specified seconds.
C. It waits for a user input for the specified seconds.
D. It sounds a beep from the computer speaker.

40 Consider the code: pid = fork(); if (pid == 0) { exec(...); }. If exec succeeds, does the child process return to execute the lines following the if block?

A. Only if the program executed returns 0.
B. Yes, always.
C. No, never.
D. Only if wait() is called.

41 In a C program, what is the data type of the variable used to store the Process ID?

A. long
B. process_id
C. pid_t
D. int

42 What is the exit status of a process if the macro WIFSIGNALED(status) returns true?

A. It is a zombie.
B. It was terminated by a signal.
C. It is currently stopped.
D. It exited normally.

43 Which signal is used to pause or stop a process (suspend execution) so it can be resumed later?

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

44 Which signal is sent to resume a process that has been stopped?

A. SIGRESUME
B. SIGSTART
C. SIGRUN
D. SIGCONT

45 Why is vfork() different from fork()?

A. vfork() creates two child processes.
B. vfork() creates a zombie directly.
C. vfork() is used only for threads.
D. In vfork(), the child shares the parent's memory address space and blocks the parent until the child calls exec() or exit().

46 Which system call is equivalent to sending a signal to oneself?

A. Both A and B
B. signal(sig)
C. raise(sig)
D. kill(getpid(), sig)

47 A process has PID 100. It calls fork() creating a child with PID 101. If process 100 calls wait(NULL), which process is it waiting for?

A. The parent of process 100.
B. Process 100 itself.
C. The init process.
D. Any child process (specifically 101 here).

48 What is the value of the constant SIG_DFL?

A. 0
B. A function pointer to a default handler.
C. A macro requesting the default signal action.
D. -1

49 When execvp(file, argv) is used, what happens if the file argument does not contain a slash (/)?

A. It searches for the file in the current directory only.
B. The call fails immediately.
C. It searches for the file in the directories specified by the PATH environment variable.
D. It searches in /bin only.

50 In the context of process synchronization, why might a parent use waitpid(pid, &status, 0) instead of wait(&status)?

A. To avoid blocking the parent.
B. To create a new child.
C. To wait for all children simultaneously.
D. To wait for a specific child process identified by pid.