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

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

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

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

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

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

A. 8
B. 2
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. 7
C. 3
D. 8

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 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. execlp()
B. execv()
C. execl()
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. execl() creates a new process, execlp() does not.
D. execlp() uses the PATH environment variable to find the executable, execl() requires the full path.

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

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

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

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

14 What is a Zombie process?

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

15 What is an Orphan process?

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

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. Restart the compiler.
B. Send the SIGKILL signal to the zombie's parent.
C. Use the clean command.
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. Running
B. Zombie
C. Ready
D. Orphan

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 prevent the creation of orphan processes.
D. To block the calling process until one of its children terminates.

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 store the exit status of the terminated child.
D. To set the waiting time duration.

21 What does wait() return on success?

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

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

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 waits indefinitely.
C. It creates a new child.
D. It returns immediately with -1.

27 What is a Signal in an operating system?

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

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

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

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

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

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

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

31 What does the signal() system call do?

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

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

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

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

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

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

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

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

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

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. sigaction()
B. sigwait()
C. sigprocmask()
D. sigqueue()

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

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

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

A. int
B. long
C. process_id
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 is a zombie.
C. It exited normally.
D. It was terminated by a signal.

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

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

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

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

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

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

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

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

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. It searches in /bin only.
B. It searches for the file in the directories specified by the PATH environment variable.
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 create a new child.
B. To wait for all children simultaneously.
C. To avoid blocking the parent.
D. To wait for a specific child process identified by pid.