Interview Questions - UNIX Process Management
5.
Predict the output of the following program code
main()
{
fork(); fork(); fork();
printf("Hello World!");
}
main()
{
fork(); fork(); fork();
printf("Hello World!");
}
Answer: "Hello World" will be printed 8 times.
Explanation: 2^n times where n is the number of calls to fork();
Explanation: 2^n times where n is the number of calls to fork();
6.
List the system calls used for process management:
System calls - Description
fork() - To create a new process
exec() - To execute a new program in a process
wait() - To wait until a created process completes its execution
exit() - To exit from a process execution
getpid() - To get a process identifier of the current process
getppid() - To get parent process identifier
nice() - To bias the existing priority of a process
brk() - To increase/decrease the data segment size of a process
fork() - To create a new process
exec() - To execute a new program in a process
wait() - To wait until a created process completes its execution
exit() - To exit from a process execution
getpid() - To get a process identifier of the current process
getppid() - To get parent process identifier
nice() - To bias the existing priority of a process
brk() - To increase/decrease the data segment size of a process
7.
How can you get/set an environment variable from a program?
Getting the value of an environment variable is done by using "getenv()".
Setting the value of an environment variable is done by using "putenv()"
Setting the value of an environment variable is done by using "putenv()"
8.
How can a parent and child process communicate?
A parent and child can communicate through any of the normal inter-process communication schemes (pipes, sockets, message queues, shared memory), but also have some special ways to communicate that take advantage of their relationship as a parent and child. One of the most obvious is that the parent can get the exit status of the child.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers