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

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

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

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

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

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. Deep Copy
B. Copy-on-Write (COW)
C. Segmentation Fault
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. 3
C. 4
D. 8

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

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

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

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

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

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

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

A. execl() creates a new process, execlp() does not.
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. execlp() is used for python scripts only.

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

A. The PID of the new program
B. 0
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. It is required to specify the path twice.
C. By convention, argv[0] is the name of the program itself.
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. fork()
D. wait()

14 What is a Zombie process?

A. A process whose parent has terminated.
B. A process that is executing an infinite loop.
C. A process that has finished execution but whose parent has not yet called wait().
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 that refuses to terminate.
D. A process created by the init system.

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

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

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. Use the clean command.
C. Restart the compiler.
D. Send the SIGKILL signal to the zombie.

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

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

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

A. To wait for I/O operations to complete.
B. To block the calling process until one of its children terminates.
C. To pause the execution of the process for a specific time.
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 send a signal to the child.
B. To store the exit status of the terminated 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. The exit status of the child
B. The PID of the terminated child
C. 0
D. 1

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

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

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

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

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

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

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

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

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

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

27 What is a Signal in an operating system?

A. A hardware interrupt.
B. A software interrupt or notification sent to a process.
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. SIGSTOP
B. SIGSEGV
C. SIGINT
D. SIGKILL

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

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

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

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

31 What does the signal() system call do?

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

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. SIGTERM
B. SIGPARENT
C. SIGUSR1
D. SIGCHLD

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

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

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

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

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

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

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

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

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 sounds a beep from the computer speaker.
C. It sleeps the process for the specified seconds.
D. It arranges for a SIGALRM signal to be delivered after 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 wait() is called.
B. Yes, always.
C. Only if the program executed returns 0.
D. No, never.

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

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

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

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

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

48 What is the value of the constant SIG_DFL?

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

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 directories specified by the PATH environment variable.
B. It searches in /bin only.
C. The call fails immediately.
D. It searches for the file in the current directory only.

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

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