Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages
Filter by Categories
nmims post
Objective Type Set
Online MCQ Assignment
Question Solution
Solved Question
Uncategorized

Linux MCQ Set 1

1. What will happen as we press the “Ctrl+c” key after running this program?

  1.    #include<stdio.h>
  2.    #include<signal.h>
  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("Aidlon");
  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

View Answer

Answer: a [Reason:] The signal handler function “response” executes after recieving the signal SIGINT. Output: [ aidlo]# gcc -o san san.c [ aidlo]# ./san Aidlo Aidlo Aidlo ^CLinux Aidlo Aidlo ^CLinux Aidlo Aidlo ^CLinux Aidlo ^Z [2]+ Stopped ./san [ aidlo]#

2. What will happen if we press “Ctrl+c” key two times after running this program?

  1.    #include<stdio.h>
  2.    #include<signal.h>
  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("Aidlon");
  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

View Answer

Answer: b [Reason:] According to the signal handler function of this program as the SIGINT signal arrives second time, the signal performs its default operation i.e. termination of the process. Output: [ aidlo]# gcc -o san san.c [ aidlo]# ./san Aidlo Aidlo ^CLinux Aidlo ^C [ aidlo]#

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

  1.    #include<stdio.h>
  2.    #include<signal.h>
  3.    #include<stdlib.h>
  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

View Answer

Answer: c [Reason:] If a process ignores a signal then by default its child also ignores that signal. Output: [ aidlo]# gcc -o san san.c [ aidlo]# ./san Parent Process Child Process Child Process ^CChild Process ^CChild Process ^CChild Process ^Z [3]+ Stopped ./san [ signal]#

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

  1.    #include<stdio.h>
  2.    #include<stdlib.h>
  3.    #include<signal.h>
  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("Aidlon");
  15.            sleep(1);
  16.        }
  17.        return 0;
  18.    }

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

View Answer

Answer: a [Reason:] The messages associated with signals can be access by the function sys_siglist(). Output: [ aidlo]# gcc -o san san.c [ aidlo]# ./san Aidlo Aidlo Aidlo ^CInterruptAidlo Aidlo ^CInterruptAidlo Aidlo ^CInterruptAidlo Aidlo Aidlo ^Z [4]+ Stopped ./san [ aidlo]#

5. In this program

  1.    #include<stdio.h>
  2.    #include<signal.h>
  3.    #include<stdlib.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.                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

View Answer

Answer: b [Reason:] The parnet process kills the child by sending a signal. Output: [ aidlo]# gcc -o san san.c [ aidlo]# ./san Child Process Child Process Child Process Child Process Child Process The child process has been killed by the parent process [ aidlo]#

6. What is the output of this program?

  1.    #include<stdio.h>
  2.    #include<signal.h>
  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

View Answer

Answer: b [Reason:] The child process sends SIGCHILD signal to its parent as it terminates. Output: [ aidlo]# gcc -o san san.c [ aidlo]# ./san Child exited [ aidlo]#

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

  1.    #include<stdio.h>
  2.    #include<signal.h>
  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

View Answer

Answer: d [Reason:] In this process the segmentation fault occurs because the memory is not allocated to the pointer *str. Output: [ aidlo]# gcc -o san san.c [ aidlo]# ./san Segmentation fault Segmentation fault (core dumped) [ aidlo]#

8. What is the output of this program?

  1.    #include<stdio.h>
  2.    #include<signal.h>
  3.    #include<stdlib.h>
  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

View Answer

Answer: a [Reason:] The SIGKILL signal can not be handled by singal handler function. Output: [ aidlo]# gcc -o san san.c [ aidlo]# ./san Killed [ aidlo]# I am an orphan process because my parent has been killed by me Handler failed

[ aidlo]#

9. This program will print

  1.    #include<stdio.h>
  2.    #include<signal.h>
  3.    #include<unistd.h>
  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("Aidlon");        
  15.        signal(SIGALRM,response);
  16.        return 0;
  17.    }

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

View Answer

Answer: b [Reason:] After 5 seconds of the execution of this program, the signal SIGALRM hits the process and handler executes. Output: [ aidlo]# gcc -o san san.c [ aidlo]# ./san Alarm clock [ aidlo]#

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

  1.     #include<stdio.h>
  2.     #include<signal.h>
  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("Aidlon");
  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

View Answer

Answer: b [Reason:] None. Output: [ sigaction]# gcc -o san san.c [ sigaction]# ./san Aidlo Aidlo Aidlo ^CLinux Aidlo Aidlo ^CLinux Aidlo ^Z [7]+ Stopped ./san [ aidlo]#

Linux MCQ Set 2

1. The redirection 2> abc implies
a) Write file 2 to file abc
b) Write standard output to abc
c) Write standard error to abc
d) None of the mentioned

View Answer

Answer: c [Reason:] None.

2. cmd 2>&1 > abc will
a) Write file2 to file1
b) Write standard output and standard error to abc
c) Write standard error to abc
d) Write standard output to abc & standard error to monitor

View Answer

Answer: d [Reason:] None.

3. cmd > abc 2>&1 will
a) Write file2 to file1
b) Write standard output and standard error to abc
c) Write standard error to abc
d) Write standard output to abc & standard error to monitor

View Answer

Answer: b [Reason:] None.

4. Which of these is the correct method for appending “foo” in /tmp/bar file?
a) echo foo > /tmp/bar
b) echo foo >> /tmp/bar
c) echo foo | /tmp/var
d) /tmp/bar < echo foo

View Answer

Answer: b [Reason:] None.

5. Syntax to suppress the display of command error to monitor?
a) command > &2
b) command 2> &1
c) command 2> &2
d) command 2> /dev/null

View Answer

Answer: d [Reason:] None.

6. The following commands gives the output like this

    #cat file1 file2
    #cat: file1: No such file or directory
    hello
    If we execute the command “cat file1 file2  1>2  2>&1” the output would be

a) cat: file1: No such file or directory hello
b) No output is displayed
c) Cat: 1>2: No such file or directory
d) hello

View Answer

Answer: b [Reason:] None.

7. cat < file1 >> file2 | file3
a) file1 content will be appended to file2 and finally stored in file3
b) file1 content will be appended to file2 and file3 will be ignored
c) file2 and file3 will have same content
d) syntax error

View Answer

Answer: d [Reason:] None.

8. Executing cat /etc/password > /dev/sda as superuser will
a) Write data into a regular file called /dev/sda
b) Write data to the physical device sda
c) Create a temporary file /dev/sda and write data to it
d) None of the mentioned

View Answer

Answer: b [Reason:] None.

9. From where would the read statement read if the following statements were executed?

   exec < file1
   exec < file2
   exec < file3
   read line

a) It would read all the files
b) It would not read any files
c) It would read all the files in reverse order
d) It would read only file3

View Answer

Answer: b [Reason:] None.

Linux MCQ Set 3

1. Which of the following time stamps need not exist for a file on traditional unix file system
a) Access Time
b) Modification Time
c) Creation Time
d) Change Time

View Answer

Answer: c [Reason:] None.

2. Which command is used to set limits on file size
a) fsize
b) flimit
c) ulimit
d) usize

View Answer

Answer: c [Reason:] None.

3. Which option of rmdir command will remove all directories a, b, c if path is a/b/c
a) –b
b) –o
c) –p
d) –t

View Answer

Answer: c [Reason:] None.

4. Which represents the user home directory
a) /
b) .
c) ..
d) ~

View Answer

Answer: d [Reason:] None.

5. If a file is removed in Unix using ‘rm’ then
a) The file can be recovered by a normal user
b) The file cannot be recovered by a user
c) The file can be fully recovered provided the sytem is not rebooted
d) The file will be moved to /lost+found directory and can be recovered only by administrator’s intervention

View Answer

Answer: b

6. Executing the ‘cd ..’ command when at the root level causes
a) Error message indicating the user can’t access beyond the root level
b) Behavior is unix-flavor dependent
c) Results in changing to the ‘home’ directory
d) Nothing happens

View Answer

Answer: d [Reason:] None.

7. How do you rename file “new” to file “old”?
a) mv new old
b) move new old
c) cp new old
d) rn new old

View Answer

Answer: a [Reason:] None.

8. What command is used to copy files and directories?
a) copy
b) cp
c) rn
d) cpy

View Answer

Answer: b [Reason:] None.

9. When mv f1 f2 is executed which file’s inode is freed?
a) f1
b) f2
c) new inode will be used
d) no inode is freed

View Answer

Answer: b [Reason:] None.

10. Any file’s attribute information is stored in which structure on the disk
a) Inode
b) Data blocks
c) File blocks
d) Directory file

View Answer

Answer: a [Reason:] None.

Linux MCQ Set 4

1. By default if any regular file is created, the number of link is displayed as 1 ?
a) True
b) False

View Answer

Answer: a [Reason:] None.

2. How many links are created when we creat a directory file?
a) 1
b) 2
c) 3
d) 4

View Answer

Answer: b [Reason:] None.

3. A user creates a link to a file file1 using the following command “ln file1 file2”. Which of the following is not true?
a) file1 and file2 have the same inode numbers
b) The number of links for file1 is displayed as 1
c) The number of links for file1 is displayed as 2
d) The number of links for file2 is displayed as 2

View Answer

Answer: b [Reason:] None.

4. There are two hard links to the “file1” say hl and h2 and a softlink sl. What happens if we deleted the “file1”?
a) We will still be able to access the file with hl and h2 but not with sl
b) We will not be able to access the file with hl and h2 but with sl
c) We will be able to access the file with any of hl, h2 and sl
d) We will not be able to access the file with any of hl, h2 and sl

View Answer

Answer: a [Reason:] None.

5. If two files on same partition point to the same inode structure they are called
a) Soft links
b) Hard links
c) Alias
d) Special files

View Answer

Answer: b [Reason:] None.

6. Deleting a soft-link
a) Deletes the destination file
b) Deletes both the softlink and the destination file
c) Deletes just the softlink
d) backup of the destination is automatically created

View Answer

Answer: c [Reason:] None.

7. Creation of hardlinks that point across partitions
a) is allowed only to root user
b) can be done by all users
c) the effects are unspecified
d) is not allowed

View Answer

Answer: d [Reason:] None.

8. Which command is used to change permissions of files and directories?
a) mv
b) chgrp
c) chmod
d) set

View Answer

Answer: c [Reason:] None.

9. Where can I find the printer in the file structure?
a) /etc
b) /dev
c) /lib
d) /printer

View Answer

Answer: b [Reason:] None.

10. Which of the following statement is true?
a) The cp command will preserve the meta data of the file
b) The sort command by default sorts in the numeric order
c) The mv command will preserve the meta data of the file
d) The command ps will display the filesystem usage

View Answer

Answer: c [Reason:] None.

11. What UNIX command is used to update the modification time of a file?
a) time
b) modify
c) cat
d) touch

View Answer

Answer: d [Reason:] None.