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. new()
D. create()

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

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

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

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

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. Copy-on-Write (COW)
B. Segmentation Fault
C. Deep Copy
D. Shared Memory Reference

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

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

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

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

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

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

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

8 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 the Parent's PID

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

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

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

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

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. It is the return type specifier.
B. By convention, argv[0] is the name of the program itself.
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. exec()
B. signal()
C. fork()
D. wait()

14 What is a Zombie process?

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

15 What is an Orphan process?

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

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

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

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

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

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

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

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

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

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 send a signal to the child.
C. To specify which child PID to wait for.
D. To set the waiting time duration.

21 What does wait() return on success?

A. 0
B. The PID of the terminated child
C. 1
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. WTERMSIG(status)
B. WIFSIGNALED(status)
C. WIFEXITED(status)
D. WEXITSTATUS(status)

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

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

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

A. wait() waits for any child, waitpid() can wait for a specific child.
B. wait() is used for threads, waitpid() for processes.
C. wait() is blocking, waitpid() is always non-blocking.
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. WNOWAIT
B. WNOHANG
C. WBLOCK
D. WUNTRACED

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

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

27 What is a Signal in an operating system?

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

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

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

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

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

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

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

31 What does the signal() system call do?

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

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

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

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

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

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

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

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

A. <unistd.h>
B. <signal.h>
C. <sys/wait.h>
D. <stdlib.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. No process.
C. Only the init process.
D. All processes in the system.

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

A. Pauses the process.
B. Sends SIGKILL (9) to 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. sigprocmask()
B. sigaction()
C. sigqueue()
D. sigwait()

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

A. It waits for a user input for the specified seconds.
B. It arranges for a SIGALRM signal to be delivered after the specified seconds.
C. It sleeps the process 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. Yes, always.
B. Only if the program executed returns 0.
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. pid_t
B. process_id
C. long
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. SIGSTOP
B. SIGINT
C. SIGTERM
D. SIGCONT

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

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

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

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

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

A. kill(getpid(), sig)
B. signal(sig)
C. Both A and B
D. raise(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. Any child process (specifically 101 here).
B. The init process.
C. The parent of process 100.
D. Process 100 itself.

48 What is the value of the constant SIG_DFL?

A. A macro requesting the default signal action.
B. 0
C. A function pointer to a default handler.
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. It searches in /bin only.
C. The call fails immediately.
D. It searches for the file in the directories specified by the PATH environment variable.

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 wait for all children simultaneously.
C. To create a new child.
D. To wait for a specific child process identified by pid.