logo
  • Home
  • Test & Rank
  • About
  • Training
  • Programming
  • CS
  • IT
  • IS
  • ECE
  • EEE
  • EE
  • Civil
  • Mechanical
  • Chemical
  • Metallurgy
  • Instrumentation
  • Aeronautical
  • Aerospace
  • Biotechnology
  • Mining
  • Marine
  • Agriculture
  • MCA
  • BCA
  • Internship
  • Jobs
  • Contact

Linux Multiple Choice Questions | MCQs | Quiz

Linux Interview Questions and Answers
Practice Linux questions and answers for interviews, campus placements, online tests, aptitude tests, quizzes and competitive exams.

Get Started

•   Linux Environment - 1
•   Linux Environment - 2
•   Linux Environment - 3
•   Linux Commands - 1
•   Linux Commands - 2
•   Linux Commands - 3
•   Linux Commands - 4
•   Linux File Management - 1
•   Linux File Management - 2
•   Linux File Types
•   Linux File Permissions - 1
•   Linux File Permissions - 2
•   Linux File System Overview
•   Linux Startup & Shutdown
•   Linux Process Management
•   User Account Management
•   Linux Shell Programming
•   Linux Shell Environment - 1
•   Linux Shell Environment - 2
•   Linux Shell Redirection
•   Shell Special Symbols
•   Linux Search Pattern
•   Linux Shell Functions
•   Linux Shell Variables
•   Bash Arithmetic Expression
•   Command History
•   Bash Built-in Commands
•   Bash Built-in Commands - 2
•   Bash Built-in Commands - 3
•   Linux vi Editor
•   Linux sed Editor
•   Awk Programming Basics
•   Programming Expressions
•   Awk Control Statements
•   Awk Variables & Arrays
•   Filesystem Hierarchy - 1
•   Filesystem Hierarchy - 2
•   Linux Proc Filesystem - 1
•   Linux Proc Filesystem - 2
•   Linux Proc Filesystem - 3
•   Linux Proc Filesystem - 4
•   Linux Proc Filesystem - 5
•   Makefile Questions - 1
•   Makefile Questions - 2
•   GCC Compiler Options - 1
•   GCC Compiler Options - 2
•   GCC Compiler Options - 3
•   GCC Compilation Stages-1
•   GCC Compilation Stages-2
•   Static Libraries Questions
•   Shared Libraries Questions
•   GDB Debugger Questions-1
•   GDB Debugger Questions-2
•   GDB Debugger Questions-3
•   GDB Debugger Questions-4
•   GDB Debugger Questions-5
•   Linux Sysfs Questions - 1
•   Linux Sysfs Questions - 2
•   Linux Sysfs Questions - 3
•   Linux Sysfs Questions - 4
•   Linux Sysfs Questions - 5
•   Linux Device Drivers
•   Linux Process Management
•   Linux Memory Management
•   Linux File Management - 1
•   Linux File Management - 2
•   Linux Signal Handling
•   Linux IPCs - 1
•   Linux IPCs - 2
•   Linux Systems
•   ↓ Debugging Questions ↓
•   Debugging Malloc/Free-1
•   Debugging Malloc/Free-2
•   Debugging File Handling
•   Process Management
•   Debugging Signal Handling
•   Debugging Userlimit/Timer
•   Debugging Posix Threads
•   PThreads Handling
•   Debugging Pipes
•   Debugging System-V IPCs
•   Debugging POSIX IPCs
•   Debugging Unix Sockets
•   Debugging Internet Sockets

Best Reference Books

•   Linux Books
« Prev Page
Next Page »

Linux Debugging Questions & Answers – fork, exec and wait System Calls

Posted on February 15, 2013 by Manish
This set of Linux Debugging questions and answers focuses on the fork, exec and wait System Calls.

1. What is the output of this program?

  1.    #include<stdio.h>
  2.  
  3.    int main()
  4.    {
  5.        fork();
  6.        printf("Sanfoundry\n");
  7.        return 0;
  8.    }

a) the string “Sanfoundry” will print 1 time
b) the string “Sanfoundry” will print 2 times
c) the string “Sanfoundry” will print 3 times
d) none of the mentioned
View Answer

Answer: b
Explanation: The “fork” system call creates a new process by duplicating the calling process. Hence the next statement is executed by two processes.
Output:
[[email protected] sanfoundry]# gcc -o san san.c
[[email protected] sanfoundry]# ./san
Sanfoundry
[[email protected] sanfoundry]# Sanfoundry

[[email protected] sanfoundry]#
advertisement

2. What is the output of this program?

  1.    #include<stdio.h>
  2.    #include<unistd.h>
  3.  
  4.    int main()
  5.    {
  6.        pid_t child;
  7.        child = fork();
  8.        printf("%d\n",child);
  9.        return 0;
  10.    }

a) it will print “0”
b) it will print the PID of the child process
c) it will print “0” & the PID of the child process
d) none of the mentioned
View Answer

Answer: c
Explanation: The “fork” system call returns the PID of the child process when it is executed by the parent process and returns 0 when it is executed by the child process.
Output:
[[email protected] sanfoundry]# gcc -o san san.c
[[email protected] sanfoundry]# ./san
17654
[[email protected] sanfoundry]# 0

[[email protected] sanfoundry]#

3. What is the output of this program?

  1.    #include<stdio.h>
  2.    #include<stdlib.h>
  3.    #include<unistd.h>
  4.  
  5.    int main()
  6.    {
  7.        pid_t child;
  8.        int status;
  9.        child = fork();
  10.        switch(child){
  11.            case -1 ;
  12.                perror("fork");
  13.                exit(1);
  14.            case 0 :
  15.                printf("%d\n",getppid());
  16.                break;
  17.            default :
  18.                printf("%d\n",getpid());
  19.                wait(&status);
  20.                break;
  21.         }
  22.         return 0;
  23.    }

a) this program will print two same integer values
b) this program will print two different integer values
c) segmentation fault
d) none of the mentioned
View Answer

Answer: a
Explanation: In this program the child process is printing its parent PID and the parent process is printing its own PID. Hence both the integer values are same.
Output:
[[email protected] sanfoundry]# gcc -o san san.c
[[email protected] sanfoundry]# ./san
17729
17729
[[email protected] sanfoundry]# ./san
17731
17731
[[email protected] sanfoundry]#

4. This program will print ____ as output.

advertisement
  1.    #include<stdio.h>
  2.    #include<stdlib.h>
  3.    #include<unistd.h>
  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.                sleep(10);
  15.                printf("%d\n",getppid());
  16.                break;
  17.            default :
  18.                break;
  19.        }
  20.        return 0;
  21.    }

a) 0
b) 1
c) an integer value except 0 and 1 i.e. PID of a process
d) none of the mentioned
View Answer

Answer: b
Explanation: In this program the parent process terminates before the child process. Hence the child process prints 1 as its parent process ID. The output of this program will appear after 10 seconds.
Output:
[[email protected] sanfoundry]# gcc -o san san.c
[[email protected] sanfoundry]# ./san
[[email protected] sanfoundry]# 1

[[email protected] sanfoundry]#

5. What is the output of this program?

  1.    #include<stdio.h>
  2.    #include<stdlib.h>
  3.    #include<unistd.h>
  4.  
  5.    int main()
  6.    {
  7.        pid_t child;
  8.        int a, status;
  9.        a = 10;
  10.        child = fork();
  11.        switch(child){
  12.            case -1 :
  13.                perror("fork");
  14.                exit(1);
  15.            case 0 :
  16.                printf("%d\n",a);
  17.                break;
  18.            default :
  19.                wait(&status);
  20.                break;
  21.        }
  22.        return 0;
  23.    }

a) 10
b) garbage value
c) segmentation fault
d) program will give an error because variable “a” is not defined in child process
View Answer

Answer: a
Explanation: The child’s stack, data and heap segments are exact duplicates of its parent process when the process is created by “fork” system call.
Output:
[[email protected] sanfoundry]# gcc -o san san.c
[[email protected] sanfoundry]# ./san
10
[[email protected] sanfoundry]#

6. What is the output of this program?

  1.    #include<stdio.h>
  2.    #include<stdlib.h>
  3.    #include<unistd.h>
  4.  
  5.    int main()
  6.    {
  7.        pid_t child;
  8.        int status;
  9.        child = fork();        
  10.            switch(child){
  11.                case -1 :
  12.                    perror("fork");
  13.                    exit(1);
  14.                case 0 :
  15.                    exit(2);
  16.                    break;
  17.                default :       
  18.                    wait(&status);
  19.                    printf("%d\n",WEXITSTATUS(status));
  20.                    break;
  21.            }
  22.            return 0;
  23.    }

a) 0
b) 1
c) 2
d) none of the mentioned
View Answer

Answer: c
Explanation: The “WEXITSTATUS” returns the low-order 8 bits of the exit status value from the child process.
Output:
[[email protected] sanfoundry]# gcc -o san san.c
[[email protected] sanfoundry]# ./san
2
[[email protected] sanfoundry]#
advertisement

7. What is the output of this progarm?

  1.    #include<stdio.h>
  2.    #include<unistd.h>
  3.  
  4.    int main()
  5.    {
  6.        execl("/bin/ls","ls",NULL);
  7.        return 0;
  8.    }

a) the program will give an compilation error
b) the program will give segmentation fault
c) the program will execute just like “ls” command
d) none of the mentioned
View Answer

Answer: c
Explanation: The “execl” system call replaces the current process image with a new process image according to the arguments.
Output:
[[email protected] sanfoundry]# gcc -o san san.c
[[email protected] sanfoundry]# ./san
san san.c
[[email protected] sanfoundry]#

8. How many time “Sanfoundry” will print in this program?

  1.    #include<stdio.h>
  2.    #include<stdlib.h>
  3.    #include<unistd.h>
  4.  
  5.    int main()
  6.    {       
  7.        if( execl("/bin/ls","ls",NULL) == -1){         
  8.            perror("execl");
  9.            exit(1);
  10.        }
  11.        printf("Sanfoundry\n");
  12.        return 0;
  13.    }

a) 0
b) 1
c) 2
d) none of the mentioned
View Answer

Answer: a
Explanation: In this program, the next statement of “execl” will never execute because the current process is replaced by the process created by the “execl” system call.
Output:
[[email protected] sanfoundry]# gcc -o san san.c
[[email protected] sanfoundry]# ./san
san san.c
[[email protected] sanfoundry]#

9. This program will create ____ child processes?

  1.    #include<stdio.h>
  2.    #include<unistd.h>
  3.  
  4.    int main()
  5.    {
  6.        fork();
  7.        fork();
  8.        fork();
  9.        printf("Sanfoundry\n");
  10.        return 0;
  11.    }

a) 3
b) 5
c) 7
d) 9
View Answer

Answer: c
Explanation: None.
Output:
[[email protected] sanfoundry]# gcc -o san san.c
[[email protected] sanfoundry]# ./san
Sanfoundry
[[email protected] sanfoundry]# Sanfoundry
Sanfoundry
Sanfoundry
Sanfoundry
Sanfoundry
Sanfoundry
Sanfoundry

[[email protected] sanfoundry]#

10. What is the output of this progarm?

  1.     #include<stdio.h>
  2.     #include<unistd.h>
  3.  
  4.     int main()
  5.     {
  6.         pid_t child;
  7.         int a, b;
  8.         a = 10;
  9.         b = 20;
  10.         child = fork();
  11.         a = a + b;
  12.         if(child > 0){
  13.             printf("%d\n",a);
  14.         } 
  15.         return 0;
  16.     }

a) 10
b) 30
c) 50
d) none of the mentioned
View Answer

Answer: b
Explanation: None.
Output:
[[email protected] sanfoundry]# gcc -o san san.c
[[email protected] sanfoundry]# ./san
30
[[email protected] sanfoundry]#

Sanfoundry Global Education & Learning Series – Linux Administration & Programming.
Here’s the list of Best Reference Books in Linux Commands & Shell Programming.
Here’s the list of Best Reference Books in Linux Kernel, Device-Drivers & System Programming.

To practice all questions on Linux Administration & Programming, here is complete set of 1000+ Multiple Choice Questions and Answers on Linux.

« Prev Page - Linux Debugging Questions & Answers – dup, fcntl, lseek and read System Calls
» Next Page - Linux Debugging Questions & Answers – Signal Handling System Calls

« Linux Debugging Questions & Answers – dup, fcntl, lseek and read System Calls
Linux Debugging Questions & Answers – Signal Handling System Calls »
advertisement

Deep Dive @ Sanfoundry:

  1. C Programming Examples on Linked List
  2. Simple C Programs
  3. C Programming Examples on Bitwise Operations
  4. Training Classes on C, Linux & SAN – Group Photos
  5. Bangalore Training – SAN, C, Linux Kernel and Device Drivers Training
  6. C# Programming Examples on Mathematics
  7. C# Programming Examples on Data Structures
  8. Linux Command Tutorials with Examples and Explanations
  9. Linux Questions and Answers
  10. C Programming Examples on Trees
Manish Bhojasia
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn | Facebook | Twitter

Best Careers

Developer Tracks
SAN Developer
Linux Kernel Developer
Linux Driver Developer
Linux Network Developer

Live Training Photos
Mentoring
Software Productivity
GDB Assignment
Sanfoundry is No. 1 choice for Deep Hands-ON Trainings in SAN, Linux & C, Kernel Programming. Our Founder has trained employees of almost all Top Companies in India such as VMware, Citrix, Oracle, Motorola, Ericsson, Aricent, HP, Intuit, Microsoft, Cisco, SAP Labs, Siemens, Symantec, Redhat, Chelsio, Cavium, ST-Micro, Samsung, LG-Soft, Wipro, TCS, HCL, IBM, Accenture, HSBC, Mphasis, Tata-Elxsi, Tata VSNL, Mindtree, Cognizant and Startups.

Best Trainings

SAN I - Technology
SAN II - Admin
Linux Fundamentals
Advanced C Training
Linux-C Debugging
System Programming
Network Programming
Linux Threads
Kernel Programming
Kernel Debugging
Linux Device Drivers

Best Reference Books

Computer Science Books
Algorithm & Programming Books
Electronics Engineering Books
Electrical Engineering Books
Chemical Engineering Books
Civil Engineering Books
Mechanical Engineering Books
Industrial Engineering Books
Instrumentation Engg Books
Metallurgical Engineering Books
All Stream Best Books

Questions and Answers

1000 C Questions & Answers
1000 C++ Questions & Answers
1000 C# Questions & Answers
1000 Java Questions & Answers
1000 Linux Questions & Answers
1000 Python Questions
1000 PHP Questions & Answers
1000 Hadoop Questions
Cloud Computing Questions
Computer Science Questions
All Stream Questions & Answers

India Internships

Computer Science Internships
Instrumentation Internships
Electronics Internships
Electrical Internships
Mechanical Internships
Industrial Internships
Systems Internships
Chemical Internships
Civil Internships
IT Internships
All Stream Internships

About Sanfoundry

About Us
Copyright
Terms
Privacy Policy
Jobs
Bangalore Training
Online Training
Developers Track
Mentoring Sessions
Contact Us
Sitemap
© 2011 Sanfoundry. All Rights Reserved.