Unit 4 - Practice Quiz

CSE325 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. spawn()
B. fork()
C. create()
D. new()

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

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

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

A. 0
B. -1
C. NULL
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. Segmentation Fault
B. Copy-on-Write (COW)
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. 3
B. 4
C. 2
D. 8

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

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

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

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

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

A. The PID remains the same
B. A new PID is assigned
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. execle()
C. execlp()
D. execl()

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

A. execl() takes an environment array, execlp() does not.
B. execlp() uses the PATH environment variable to find the executable, execl() requires the full path.
C. execlp() is used for python scripts only.
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. 1
D. It does not return

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

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

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

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

14 What is a Zombie process?

A. A process that is executing an infinite loop.
B. A process that has finished execution but whose parent has not yet called wait().
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 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 init process (PID 1)
B. The shell
C. The zombie process
D. The swapper process

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. Restart the compiler.
C. Send the SIGKILL signal to the zombie.
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. Ready
C. Zombie
D. Running

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

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

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

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

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. WTERMSIG(status)
B. WIFSIGNALED(status)
C. WEXITSTATUS(status)
D. WIFEXITED(status)

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

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

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

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

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 hardware interrupt.
C. A network packet.
D. A synchronization primitive for threads.

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

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

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. signal()
B. send()
C. kill()
D. raise()

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. Ignore the signal
C. Terminate the process and dump core
D. Stop the process

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

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

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

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

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

A. <signal.h>
B. <stdlib.h>
C. <unistd.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. No process.
B. All processes in the same process group as the sender.
C. All processes in the system.
D. Only the init process.

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

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

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

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

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

A. It sounds a beep from the computer speaker.
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 waits for a user input for the specified seconds.

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. No, never.
C. Yes, always.
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. int
B. long
C. pid_t
D. process_id

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

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

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

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

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

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

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

A. vfork() creates a zombie directly.
B. vfork() is used only for threads.
C. vfork() creates two child processes.
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. raise(sig)
B. kill(getpid(), sig)
C. signal(sig)
D. Both A and B

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 parent of process 100.
C. Process 100 itself.
D. The init process.

48 What is the value of the constant SIG_DFL?

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

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

A. The call fails immediately.
B. It searches for the file in the current directory only.
C. It searches in /bin only.
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 wait for a specific child process identified by pid.
D. To create a new child.