Unit 4 - Practice Quiz
1 Which system call is used to create a new process in Unix-like operating systems?
2
What is the return value of fork() in the child process?
3
If fork() fails to create a new process, what value does it return?
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?
5
Consider the following code snippet. How many times will "Hello" be printed?
fork();
fork();
printf("Hello\n");
6
If a C program executes fork(); three times sequentially (fork(); fork(); fork();), how many new processes are created?
7
Which header file is primarily required to use the fork() system call?
8
What happens to the Process ID (PID) after a successful exec() call?
9
Which of the following exec functions expects the arguments as a NULL-terminated array of pointers?
10
What is the primary difference between execl() and execlp()?
execl() takes an environment array, execlp() does not.
execlp() uses the PATH environment variable to find the executable, execl() requires the full path.
execlp() is used for python scripts only.
execl() creates a new process, execlp() does not.
11
If exec() is successful, what value does it return to the calling function?
12
In the command execl("/bin/ls", "ls", "-l", NULL);, why is "ls" passed as the second argument?
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?
14 What is a Zombie process?
wait().
15 What is an Orphan process?
init system.
16 Which process usually adopts an orphan process in a classic Unix system?
17 How can a system administrator remove a Zombie process from the process table?
clean command.
18
Which state does a process enter immediately after the exit() system call if the parent is sleeping?
19
What is the primary purpose of the wait() system call?
20
What is the parameter passed to the wait(int *status) system call used for?
21
What does wait() return on success?
22
Which macro is used to check if a child process terminated normally (i.e., by calling exit or returning from main)?
23
If WIFEXITED(status) is true, which macro extracts the actual exit code (0-255) returned by the child?
24
What is the difference between wait() and waitpid()?
wait() is used for threads, waitpid() for processes.
wait() is blocking, waitpid() is always non-blocking.
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)?
26
What happens if a parent process calls wait() but has no child processes?
27 What is a Signal in an operating system?
28
Which signal is sent to a process when the user presses Ctrl+C in the terminal?
29 Which of the following signals cannot be caught or ignored?
30 Which system call is used to send a signal to a specific process?
31
What does the signal() system call do?
32
What is the default action for SIGSEGV (Segmentation Fault)?
33 Which signal is sent to a parent process when a child process terminates?
34
What does the handler SIG_IGN do when passed to the signal() function?
35
Which header file defines standard signal names like SIGINT and SIGKILL?
36
In the kill(pid_t pid, int sig) system call, if pid is 0, to whom is the signal sent?
37
What does the command kill -9 <pid> do in a shell?
38
Which function is a more robust and modern alternative to signal() for handling signals?
39
What is the effect of alarm(unsigned int seconds) system call?
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?
wait() is called.
41 In a C program, what is the data type of the variable used to store the Process ID?
42
What is the exit status of a process if the macro WIFSIGNALED(status) returns true?
43 Which signal is used to pause or stop a process (suspend execution) so it can be resumed later?
44 Which signal is sent to resume a process that has been stopped?
45
Why is vfork() different from fork()?
vfork() creates a zombie directly.
vfork() is used only for threads.
vfork() creates two child processes.
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?
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?
48
What is the value of the constant SIG_DFL?
49
When execvp(file, argv) is used, what happens if the file argument does not contain a slash (/)?
/bin only.
50
In the context of process synchronization, why might a parent use waitpid(pid, &status, 0) instead of wait(&status)?
pid.