1.
What is the output of this program?
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
int main()
{
pid_t child;
int status;
child = fork();
switch(child){
case -1 ;
perror("fork");
exit(1);
case 0 :
printf("%d\n",getppid());
break;
default :
printf("%d\n",getpid());
wait(&status);
break;
}
return 0;
}
Answer: Option 'A'
this program will print two same integer values
2.
This program will print ____ as output.
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
int main()
{
pid_t child;
child = fork();
switch(child){
case -1 :
perror("fork");
exit(1);
case 0 :
sleep(10);
printf("%d\n",getppid());
break;
default :
break;
}
return 0;
}
Answer: Option 'B'
1
3.
What is the output of this program?
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
int main()
{
pid_t child;
int a, status;
a = 10;
child = fork();
switch(child){
case -1 :
perror("fork");
exit(1);
case 0 :
printf("%d\n",a);
break;
default :
wait(&status);
break;
}
return 0;
}
Answer: Option 'A'
10
4.
What is the output of this program?
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
int main()
{
pid_t child;
int status;
child = fork();
switch(child){
case -1 :
perror("fork");
exit(1);
case 0 :
exit(2);
break;
default :
wait(&status);
printf("%d\n",WEXITSTATUS(status));
break;
}
return 0;
}
Answer: Option 'C'
2
5.
What is the output of this progarm?
#include<stdio.h>
#include<unistd.h>
int main()
{
execl("/bin/ls","ls",NULL);
return 0;
}
Answer: Option 'C'
the program will execute just like “ls” command
6.
How many time “Sanfoundry” will print in this program?
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
int main()
{
if( execl("/bin/ls","ls",NULL) == -1){
perror("execl");
exit(1);
}
printf("Sanfoundry\n");
return 0;
}
Answer: Option 'A'
0
7.
This program will create ____ child processes?
#include<stdio.h>
#include<unistd.h>
int main()
{
fork();
fork();
fork();
printf("Sanfoundry\n");
return 0;
}
Answer: Option 'C'
7
8.
What is the output of this progarm?
#include<stdio.h>
#include<unistd.h>
int main()
{
pid_t child;
int a, b;
a = 10;
b = 20;
child = fork();
a = a + b;
if(child > 0){
printf("%d\n",a);
}
return 0;
}
Answer: Option 'B'
30