What is the output of this program?
#include<stdio.h>
#include<stdlib.h>
int main()
{
int fd[2];
int child;
char buff[6];
if(pipe(fd) != 0)
perror("pipe");
child=fork();
switch(child){
case -1 :
perror("fork");
exit(1);
case 0 :
if (write(fd[1],"Linux",6) != 6)
perror("write");
break;
default :
read(fd[0],buff,6);
printf("%s\n",buff);
break;
}
return 0;
}
#include<stdio.h>
#include<stdlib.h>
int main()
{
int fd[2];
int child;
char buff[6];
if(pipe(fd) != 0)
perror("pipe");
child=fork();
switch(child){
case -1 :
perror("fork");
exit(1);
case 0 :
if (write(fd[1],"Linux",6) != 6)
perror("write");
break;
default :
read(fd[0],buff,6);
printf("%s\n",buff);
break;
}
return 0;
}
A. this program will print the string "Linux"
B. this program will print nothing
C. segmentation fault
D. none of the mentioned
Answer: Option A
Related Questions on Linux
What command is used to count the total number of lines, words, and characters contained in a file?
A. countw
B. wcount
C. wc
D. count p
E. None of the above
What command is used with vi editor to delete a single character?
A. x
B. y
C. a
D. z
E. None of the above
Join The Discussion