250+ TOP MCQs on dup, fcntl, lseek and read System Calls and Answers

Linux Debugging questions and answers focuses on dup, fcnlt, lseek and read System Calls.1. What is the output of this program?

  1.    #include
  2.    #include
  3. 
    
  4.    int main()
  5.    {
  6.        pid_t fd;
  7.        char ch;
  8.        int count;
  9.        fd = open("san.c",O_RDONLY);
  10.        do{
  11.            count = read(fd,&ch,1);
  12.            printf("%c",ch);
  13.        }while(count);
  14.        return 0;
  15.    }

a) it will print nothing
b) it will print the source code of the source file “san.c”
c) segmentation fault
d) none of the mentioned

Answer: b

2. What is the output of this program?

  1.    #include
  2.    #include
  3. 
    
  4.    int main()
  5.    {
  6.        int fd, count;
  7.        fd = open(".txt",O_WRONLY|O_CREAT);
  8.        count = write(fd,"Linux System Programming",5);
  9.        if(count != 5)
  10.            perror("write");
  11.        return 0;
  12.    }

a) it will create a file “.txt” in the present working directory
b) it will write the string “Linux System Programming” in the file “.txt”
c) all of the mentioned
d) none of the mentioned

Answer: a

3. What is the output of this program?

  1.    #include
  2.    #include
  3. 
    
  4.    int main()
  5.    {
  6.        int fd, count;
  7.        fd = open("san.c",O_RDONLY);
  8.        count = write(fd,"Linux",5);
  9.        if(count != 5)
  10.            perror("write");
  11.        return 0;
  12.    }

a) it will write the string “Linux” in the beginning of source file “san.c”
b) it will write the string “Linux” in the end of the source file “san.c”
c) segmentation fault
d) none of the mentioned

Answer: d

4. What is the output of this program?

  1.    #include
  2.    #include
  3.    #include
  4. 
    
  5.    int main()
  6.    {
  7.        int fd, count;
  8.        char ch, *buff;
  9.        buff = (char *)malloc(sizeof(char)*10);
  10.        fd = open("san.c",O_RDONLY);
  11.        count = read(fd,buff,5);
  12.        printf("%dn",count);
  13.        return 0;
  14.    }

a) 5
b) 10
c) 0
d) -1

Answer: a

5. In the output of this program, the string “/* Linux */” will be added at the ____ of the source file.

  1.    #include
  2.    #include
  3.    #include
  4. 
    
  5.    int main()
  6.    {
  7.        int fd;
  8.        fd = open("san.c",O_RDWR|O_APPEND);
  9.        write(fd,"/* Linux */",11);
  10.        return 0;
  11.    }

a) end
b) beginning
c) second line
d) third line

Answer: a

6. What is the output of this program?

  1.    #include
  2.    #include
  3.    #include
  4. 
    
  5.    int main()
  6.    {
  7.        int fd;
  8.        char *buff;
  9.        buff = (char *)malloc(sizeof(char)*5);
  10.        fd = open(".txt",O_RDWR|O_CREAT);
  11.        write(fd,"Linux",5);
  12.        read(fd,buff,5);
  13.        printf("%sn",buff);
  14.    }

a) it will print nothing
b) it will print the string “Linux”
c) segmentation fault
d) none of the mentioned

Answer: a

7. What is the output of this program?

  1.    #include
  2.    #include
  3. 
    
  4.    int main()
  5.    {
  6.        int fd, count;
  7.        char ch;
  8.        fd = open(".txt",O_RDWR|O_CREAT);
  9.        write(fd,"s",1);
  10.        lseek(fd,0,SEEK_SET);
  11.        write(fd,"d",1);
  12.        lseek(fd,0,0);
  13.        read(fd,&ch,1);
  14.        printf("%cn",ch);
  15.        return 0;
  16.    }

a) d
b) s
c) sd
d) none of the mentioned

Answer: d

8. What is the output of this program?

  1.    #include
  2.    #include
  3. 
    
  4.    int main()
  5.    {
  6.        int fd, count;
  7.        char ch[10];
  8.        fd = open(".txt",O_RDWR|O_CREAT);
  9.        write(fd,"linux",5);
  10.        lseek(fd,2,SEEK_END);
  11.        write(fd,"san",3);
  12.        lseek(fd,0,0);
  13.        count = read(fd,ch,10);
  14.        printf("%sn",ch);
  15.        return 0;
  16.    }

a) linux
b) linuxsan
c) linux san
d) none of the mentioned

Answer: a

9. What is the output of this program?

  1.    #include
  2.    #include
  3.    #include
  4. 
    
  5.    int main()
  6.    {
  7.        int fd, new_fd;
  8.        char *buff;
  9.        buff = (char *)malloc(sizeof(char)*8);
  10.        fd = open("san.c",O_RDONLY);
  11.        new_fd = dup(fd);
  12.        close(fd);
  13.        read(new_fd,buff,8);
  14.        printf("%sn",buff);
  15.    }

a) this program will not print anything
b) this program will print “#include”
c) this program will give the segmentation fault
d) this program will give the syntax error

Answer: b

10. What is the output of this program?

  1.     #include
  2.     #include
  3. 
    
  4.     int main()
  5.     {
  6.         int fd, fd2, ret;
  7.         fd = open("san.c",O_RDONLY);
  8.         ret = close(fd2);
  9.         printf("%dn",ret);
  10.     }

a) 0
b) 1
c) -1
d) none of the mentioned

Answer: c
  250+ TOP MCQs on User Account Management and Answers

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top