In: Computer Science
When the following statements are executed, what is the output from the child process? You may assume all variables have been properly declared and all function calls are successful.
var2 = 200; var3 = 300; var1 = fork(); if ( var1 > 0 ) { printf("%d\n", var2); } else { printf("%d\n", var3); }
200 |
||
1 |
||
0 |
||
300 |
||
100 |
A process that has terminated, but whose parent has not yet called wait(), is known as a __________ process.
zombie |
||
terminated |
||
false |
||
init |
In Unix/Linux, a process can run the __________ system call to load another executable to its memory image.
wait() |
||
exit() |
||
fork() |
||
exec() |
When the following statements are executed, what is the output
from the child process?
You may assume all variables have been properly declared and all
function calls are successful.
var2 = 200;
var3 = 300;
var1 = fork();
if ( var1 > 0 )
{
printf("%d\n", var2);
}
else
{
printf("%d\n", var3);
}
Answer: 0
(zero)
Explanation:
fork() system call is used to create a new process in unix.
fork()
call returns twice. It returns in both process calling fork()
and
in the newly created process. Child process returns zero
and the parent process returns a number greater than zero.
-------------------
A process that has terminated, but whose parent has not yet called wait(), is known as a __________ process.
Answer: Zombie
A zombie process is a process that has completed but still has an entry in the process table.
-------------------
In Unix/Linux, a process can run the __________ system call to load another executable to its memory image.
Answer: exec()
exec() runs an executable file in the context of an already existing process, replacing the previous executable.