Professional Documents
Culture Documents
Quiz – 1
Name:
Reg No:
Section:
Q1: The getpid() function returns the process ID of the process calling it. What is the
output of the following code [4]?
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
int main(void) {
int childpid;
int mypid;
childpid = fork();
if (childpid == -1) {
perror("Failed to fork");
return 1;
}
mypid = getpid();
if (childpid == 0)
printf("I am child %d, ID = %d\n", getpid(), mypid);
else
printf("I am parent %d, ID = %d\n",getpid(), mypid);
return 0;
}
Q2: Write the code for a program that creates a child process to run the following program
[6]:
ps -x -u