250+ TOP MCQs on Posix Threads and Answers

Linux Debugging questions and answers focuses on Posix Threads.1. Which one of the following string will print first by this program?

  1.    #include
  2.    #include
  3. 
    
  4.    void *fun_t(void *arg);
  5.    void *fun_t(void *arg)
  6.    {
  7.        printf("n");
  8.        pthread_exit("Bye");
  9.    }
  10.    int main()
  11.    {
  12.        pthread_t pt;
  13.        void *res_t;
  14.        if(pthread_create(&pt,NULL,fun_t,NULL) != 0)
  15.            perror("pthread_create");
  16.        printf("Linuxn");
  17.        if(pthread_join(pt,&res_t) != 0)
  18.            perror("pthread_join");
  19.        return 0;
  20.    }

a) Linux
b)
c) it can not be predicted
d) none of the mentioned

Answer: b

2. What is the output of this program?

  1.    #include
  2.    #include
  3. 
    
  4.    void *fun_t(void *arg);
  5.    void *fun_t(void *arg)
  6.    {
  7.        int ret;
  8.        ret = pthread_exit("Bye");
  9.        printf("%dn",ret);
  10.    }
  11.    int main()
  12.    {
  13.        pthread_t pt;
  14.        void *res_t;
  15.        if(pthread_create(&pt,NULL,fun_t,NULL) != 0)
  16.            perror("pthread_create");
  17.        if(pthread_join(pt,&res_t) != 0)
  18.            perror("pthread_join");
  19.        return 0;
  20.    }

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

Answer: d

3. What is the output of this program?

  1.    #include
  2.    #include
  3. 
    
  4.    void *fun_t(void *arg);
  5.    void *fun_t(void *arg)
  6.    {
  7.        printf("n");
  8.        pthread_exit("Bye");
  9.    }
  10.    int main()
  11.    {
  12.        pthread_t pt;
  13.        void *res_t;
  14.        if(pthread_create(&pt,NULL,fun_t,NULL) != 0)
  15.            perror("pthread_create");
  16.        return 0;
  17.    }

a) this program will print the string “”
b) this program will print nothing
c) segmentation fault
d) run time error

Answer: b

4. What is the output of this program?

  1.    #include
  2.    #include
  3. 
    
  4.    void *fun_t(void *arg);
  5.    void *fun_t(void *arg)
  6.    {
  7.        printf("%dn",a);
  8.        pthread_exit("Bye");
  9.    }
  10.    int main()
  11.    {
  12.        int a;
  13.        pthread_t pt;
  14.        void *res_t;
  15.        a = 10;
  16.        if(pthread_create(&pt,NULL,fun_t,NULL) != 0)
  17.            perror("pthread_create");
  18.        if(pthread_join(pt,&res_t) != 0)
  19.            perror("pthread_join");
  20.        return 0;
  21.    }

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

Answer: d

5. What is the output of this program?

  1.    #include
  2.    #include
  3. 
    
  4.    int a;
  5.    void *fun_t(void *arg);
  6.    void *fun_t(void *arg)
  7.    {
  8.        printf("%dn",a);
  9.        pthread_exit("Bye");
  10.    }
  11.    int main()
  12.    {
  13.        pthread_t pt;
  14.        void *res_t;
  15.        a = 10;
  16.        if(pthread_create(&pt,NULL,fun_t,NULL) != 0)
  17.            perror("pthread_create");
  18.        if(pthread_join(pt,&res_t) != 0)
  19.            perror("pthread_join");
  20.        return 0;
  21.    }

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

Answer: a

6. What is the output of this program?

  1.    #include
  2.    #include
  3. 
    
  4.    int a;
  5.    void *fun_t(void *arg);
  6.    void *fun_t(void *arg)
  7.    {
  8.        a = 20;
  9.        pthread_exit("Bye");
  10.    }
  11.    int main()
  12.    {
  13.        pthread_t pt;
  14.        void *res_t;
  15.        a = 10;
  16.        if(pthread_create(&pt,NULL,fun_t,NULL) != 0)
  17.            perror("pthread_create");
  18.        if(pthread_join(pt,&res_t) != 0)
  19.            perror("pthread_join");
  20.        printf("%dn",a);
  21.        return 0;
  22.    }

a) 10
b) 20
c) segmentation fault
d) none of the mentioned

Answer: b

7. Which one of the following statement is not true about this program?

  1.    #include
  2.    #include
  3. 
    
  4.    void *fun_t(void *arg);
  5.    void *fun_t(void *arg)
  6.    {
  7.        printf("%dn",getpid());
  8.        pthread_exit("Bye");
  9.    }
  10.    int main()
  11.    {
  12.        pthread_t pt;
  13.        void *res_t;
  14.        if(pthread_create(&pt,NULL,fun_t,NULL) != 0)
  15.            perror("pthread_create");
  16.        if(pthread_join(pt,&res_t) != 0)
  17.            perror("pthread_join");
  18.        printf("%dn",getpid());
  19.        return 0;
  20.    }

a) both printf statements will print the same value
b) both printf statements will print the different values
c) this program will print nothing
d) none of the mentioned

Answer: a

8. What is the output of this program?

  1.    #include
  2.    #include
  3.    #include
  4. 
    
  5.    int fd;
  6.    void *fun_t(void *arg);
  7.    void *fun_t(void *arg)
  8.    {
  9.        char buff[10];
  10.        int count;
  11.        count = read(fd,buff,10);
  12.        printf("%dn",count);
  13.        pthread_exit("Bye");
  14.    }
  15.    int main()
  16.    {
  17.        pthread_t pt;
  18.        void *res_t;
  19.        fd = open("san.c",O_RDONLY);
  20.        if(pthread_create(&pt,NULL,fun_t,NULL) != 0)
  21.            perror("pthread_create");
  22.        if(pthread_join(pt,&res_t) != 0)
  23.            perror("pthread_join");
  24.        return 0;
  25.    }

a) 10
b) 0
c) -1
d) segmentation fault

Answer: a

9. What is the output of this program?

  1.    #include
  2.    #include
  3.    #include
  4. 
    
  5.    void *fun_t(void *arg);
  6.    void *fun_t(void *arg)
  7.    {
  8.        pthread_exit("Bye");
  9.        printf("n");
  10.    }
  11.    int main()
  12.    {
  13.        pthread_t pt;
  14.        void *res_t;
  15.        if(pthread_create(&pt,NULL,fun_t,NULL) != 0)
  16.            perror("pthread_create");
  17.        if(pthread_join(pt,&res_t) != 0)
  18.            perror("pthread_join");
  19.        printf("%sn",res_t);
  20.        return 0;
  21.    }

a)
b) Bye
c) segementation fault
d) run time error

Answer: b

10. What is the output of this program?

  1.     #include
  2.     #include
  3. 
    
  4.     void *fun_t(void *arg);
  5.     void *fun_t(void *arg)
  6.     {
  7.         sleep(1);
  8.     }
  9.     int main()
  10.     {
  11.         pthread_t pt;
  12.         void *res_t;
  13.         if(pthread_create(&pt,NULL,fun_t,NULL) != 0)
  14.             perror("pthread_create");
  15.         if(pthread_join(pt,&res_t) != 0)
  16.             perror("pthread_join");
  17.         printf("%sn",res_t);
  18.         return 0;
  19.     }

a) this process will pause
b) segmentation fault
c) run time error
d) none of the mentioned

Answer: b
  250+ TOP MCQs on Internet Domain Socket System Calls and Answers

Leave a Comment

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

Scroll to Top