1.
What is the output of this program?
#include<stdio.h>
#include<fcntl.h>
int main()
{
pid_t fd;
char ch;
int count;
fd = open("san.c",O_RDONLY);
do{
count = read(fd,&ch,1);
printf("%c",ch);
}while(count);
return 0;
}
2.
What is the output of this program?
#include<stdio.h>
#include<fcntl.h>
int main()
{
int fd, count;
fd = open("sanfoundry.txt",O_WRONLY|O_CREAT);
count = write(fd,"Linux System Programming",5);
if(count != 5)
perror("write");
return 0;
}
3.
What is the output of this program?
#include<stdio.h>
#include<fcntl.h>
int main()
{
int fd, count;
fd = open("san.c",O_RDONLY);
count = write(fd,"Linux",5);
if(count != 5)
perror("write");
return 0;
}
4.
What is the output of this program?
#include<stdio.h>
#include<stdlib.h>
#include<fcntl.h>
int main()
{
int fd, count;
char ch, *buff;
buff = (char *)malloc(sizeof(char)*10);
fd = open("san.c",O_RDONLY);
count = read(fd,buff,5);
printf("%d\n",count);
return 0;
}
5.
In the output of this program, the string “/* Linux */” will be added at the ____ of the source file.
#include<stdio.h>
#include<stdlib.h>
#include<fcntl.h>
int main()
{
int fd;
fd = open("san.c",O_RDWR|O_APPEND);
write(fd,"/* Linux */",11);
return 0;
}
6.
What is the output of this program?
#include<stdio.h>
#include<stdlib.h>
#include<fcntl.h>
int main()
{
int fd;
char *buff;
buff = (char *)malloc(sizeof(char)*5);
fd = open("sanfoundry.txt",O_RDWR|O_CREAT);
write(fd,"Linux",5);
read(fd,buff,5);
printf("%s\n",buff);
}
7.
What is the output of this program?
#include<stdio.h>
#include<fcntl.h>
int main()
{
int fd, count;
char ch;
fd = open("sanfoundry.txt",O_RDWR|O_CREAT);
write(fd,"s",1);
lseek(fd,0,SEEK_SET);
write(fd,"d",1);
lseek(fd,0,0);
read(fd,&ch,1);
printf("%c\n",ch);
return 0;
}
8.
What is the output of this program?
#include<stdio.h>
#include<fcntl.h>
int main()
{
int fd, count;
char ch[10];
fd = open("sanfoundry.txt",O_RDWR|O_CREAT);
write(fd,"linux",5);
lseek(fd,2,SEEK_END);
write(fd,"san",3);
lseek(fd,0,0);
count = read(fd,ch,10);
printf("%s\n",ch);
return 0;
}
9.
What is the output of this program?
#include<stdio.h>
#include<stdlib.h>
#include<fcntl.h>
int main()
{
int fd, new_fd;
char *buff;
buff = (char *)malloc(sizeof(char)*8);
fd = open("san.c",O_RDONLY);
new_fd = dup(fd);
close(fd);
read(new_fd,buff,8);
printf("%s\n",buff);
}