250+ TOP MCQs on Signal Handling System Calls and Answers

Linux Debugging questions and answers focuses on signal handling System Calls.1. What will happen as we press the “Ctrl+c” key after running this program?

  1.    #include
  2.    #include
  3. 
    
  4.    void response (int);
  5.    void response (int sig_no)
  6.    {
  7.        printf("Linuxn");
  8.    }
  9.    int main()
  10.    {
  11.        signal(SIGINT,response);
  12.        while(1){
  13.            printf("n");
  14.            sleep(1);
  15.        }
  16.        return 0;
  17.    }

a) the string “Linux” will print
b) the process will be terminated after printing the string “Linux”
c) the process will terminate
d) none of the mentioned

Answer: a
2. What will happen if we press “Ctrl+c” key two times after running this program?
  1.    #include
  2.    #include
  3. 
    
  4.    void response(int);
  5.    void response(int sig_no)
  6.    {
  7.        printf("Linuxn");
  8.        signal(SIGINT,SIG_DFL);
  9.    }
  10.    int main()
  11.    {
  12.        signal(SIGINT,response);
  13.        while(1){
  14.            printf("n");
  15.            sleep(1);
  16.        }
  17.        return 0;
  18.    }

a) process will terminate in the first time
b) process will terminate in the second time
c) process will never terminate
d) none of the mentioned

Answer: b

3. What happens as the SIGINT signal hits the running process of this program?

  1.    #include
  2.    #include
  3.    #include
  4. 
    
  5.    int main()
  6.    {
  7.        pid_t child;
  8.        signal(SIGINT,SIG_IGN);
  9.        child=fork();
  10.        switch(child){
  11.            case -1:
  12.                perror("fork");
  13.                exit(1);
  14.            case 0:
  15.                while(1){
  16.                    printf("Child Processn");
  17.                    sleep(1);
  18.                }
  19.                break;
  20.            default :
  21.                while(1){
  22.                    printf("Parent Processn");
  23.                    pause();
  24.                }
  25.                break;
  26.        }
  27.        return 0;
  28.    }

a) child process terminates
b) parent process terminates
c) both child and parent process ignores the signal
d) none of the mentioned

Answer: c

4. What will print as the SIGINT signal hits the running process of this program?

  1.    #include
  2.    #include
  3.    #include
  4. 
    
  5.    void response (int);
  6.    void response (int sig_no)
  7.    {
  8.        printf("%s",sys_siglist[sig_no]);
  9.    }
  10.    int main()
  11.    {
  12.        signal(SIGINT,response);
  13.        while(1){
  14.            printf("n");
  15.            sleep(1);
  16.        }
  17.        return 0;
  18.    }

a) Interrupt
b) Stop
c) Terminate
d) none of the mentioned

Answer: a

5. In this program

  1.    #include
  2.    #include
  3.    #include
  4. 
    
  5.    int main()
  6.    {
  7.        pid_t child;
  8.        child=fork();
  9.        switch(child){
  10.            case -1 :
  11.                perror("fork");
  12.                exit(1);
  13.            case 0 :
  14.                while(1){
  15.                    printf("Child Processn");
  16.                    sleep(1);
  17.                }
  18.                break;
  19.            default :
  20.                sleep(5);
  21.                kill(child,SIGINT);
  22.                printf("The child process has been killed by the parent processn");
  23.                break;
  24.        }
  25.        return 0;
  26.    }

a) the child process kills the parent process
b) the parent process kills the child process
c) both the processes are killed by each other
d) none of the mentioned

Answer: b

6. What is the output of this program?

  1.    #include
  2.    #include
  3. 
    
  4.    void response (int);
  5.    void response (int sig_no)
  6.    {
  7.        printf("%sn",sys_siglist[sig_no]);
  8.    }
  9.    int main()
  10.    {
  11.        pid_t child;
  12.        int status;
  13.        child = fork();
  14.        switch(child){
  15.            case -1:
  16.                perror("fork");
  17.            case 0:
  18.                break;
  19.            default :
  20.                signal(SIGCHLD,response);
  21.                wait(&status);
  22.                break;
  23.        }
  24.    }

a) this program will print nothing
b) this program will print “Child Exited”
c) segmentation fault
d) none of the mentioned

Answer: b

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

  1.    #include
  2.    #include
  3. 
    
  4.    void response (int);
  5.    void response (int signo)
  6.    {
  7.        printf("%sn",sys_siglist[signo]);
  8.        signal(SIGSEGV,SIG_IGN);
  9.    }
  10.    int main()
  11.    {
  12.        signal (SIGSEGV,response);
  13.        char *str;
  14.        *str = 10;
  15.        return 0;
  16.    }

a) kernel sends SIGSEGV signal to a process as segmentation fault occurs
b) in this process signal handler will execute only one time of recieving the signal SIGSEGV
c) all of the mentioned
d) none of the mentioned

Answer: d

8. What is the output of this program?

  1.    #include
  2.    #include
  3.    #include
  4. 
    
  5.    void response (int);
  6.    void response (int sig_no)
  7.    {
  8.        printf("%sn",sys_siglist[sig_no]);
  9.        printf("This is singal handlern");
  10.    }
  11.    int main()
  12.    {
  13.        pid_t child;
  14.        int status;
  15.        child = fork();
  16.        switch (child){
  17.            case -1 :
  18.                perror("fork");
  19.                exit (1);
  20.            case 0 :
  21.                kill(getppid(),SIGKILL);
  22.                printf("I am an orphan process because my parent has been killed by men");
  23.                printf("Handler failedn");
  24.                break;
  25.            default :
  26.                signal(SIGKILL,response);
  27.                wait(&status);
  28.                printf("The parent process is still aliven");
  29.                break;
  30.        }
  31.        return 0;
  32.    }

a) the child process kills the parent process
b) the parent process kills the child process
c) handler function executes as the signal arrives to the parent process
d) none of the mentioned

Answer: a

9. This program will print

  1.    #include
  2.    #include
  3.    #include
  4. 
    
  5.    void response (int);
  6.    void response (int sig_no)
  7.    {
  8.        printf("%s is workingn",sys_siglist[sig_no]);
  9.    }
  10.    int main()
  11.    {
  12.        alarm(5);
  13.        sleep(50);
  14.        printf("n");
  15.        signal(SIGALRM,response);
  16.        return 0;
  17.    }

a) “”
b) “Alarm clock”
c) nothing
d) none of the mentioned

Answer: b

10. What happnes as the signal SIGINT hits the current process in the program?

  1.     #include
  2.     #include
  3. 
    
  4.     void response (int);
  5.     void response (int sig_no)
  6.     {
  7.         printf("Linuxn");
  8.     }
  9.     int main()
  10.     {
  11.         struct sigaction act;
  12.         act.sa_handler = response;
  13.         act.sa_flags = 0;
  14.         sigemptyset(&act.sa_mask);
  15.         sigaction(SIGINT,&act,0);
  16.         while(1){
  17.             printf("n");
  18.             sleep(1);
  19.         }
  20.         return 0;
  21.     }

a) the process terminates
b) the string “Linux” prints
c) the string “Linux” prints and then process terminates
d) none of the mentioned

Answer: b

Leave a Reply

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