1 What is the difference between fork and vfork system calls
1. What is the difference between fork and vfork system calls?
2. Describe the functionality of each of the following system calls:
a. kill(456, 0);
b. waitpid(-1,&status, 0);
c. raise(SIGUSR1);
3. What is the difference between the execlp and execvp system calls?
4. Describe how to use sigaction such that a process receiving a signal can know the pid of the originating process of this signal.
5. Describe how to use sigaction such that a process can send a payload with the signal that can be retrieved by the receiving process.
Solution
Please find the answers below:
1) fork creates a child process which is an excat copy of its parent process, which includes copying of all parent process\'s memory also. Thus makes it lilttle expensive. Whereas vfork is another system call which is similiar to fork by creating a quick copy of parent process but it doesn\'t copy the parent process\'s memory space. Thus makes this system call not expensive.
2 a) kill(456, 0) : kill is a system call which is used for sending a signal to another process. kill accepts 2 arguments, the first is process id(pid), then the signal(sig). If the pid is positive, then the signal sig will be sent to the process with id pid. If pid is 0, then the sig will be sent to every process in its group. If sig is 0, then no signal is send, but instead only error checking is performed. So here kill(456,0), the sig is 0, thus only error checking is performed.
2 b) waitpid(-1,&status, 0) : The waitpid system call will suspends the execution of the current process, untill a specified child changes its state. Here by returning -1, it is indicating that there are no children to wait for.
2 c) raise(SIGUSR1) : raise system call will do nothing but just raise/generate a signal SIGUSR1. This can also be used as a signal handler, thus this signal will be processed by that signal handler.
3) Generally the exec system calls will replace the current process image with a new process image. In execlp, the l represents the command line arguments will be passed individually to the function, and p denotes path environmental variable will be used to find the filename specified in the argument. Whereas the vp in execvp denotes that: v denotes the command line arguments are pass as a vector of pointers to the function, and p denotes same as in later.
