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. To feed standard output of one command to standard input of another in a single shell session
a) IO redirection can be used
b) Named pipes can be used
c) The pipe operator provided by the shell can be used
d) It can not be done

View Answer

Answer: c [Reason:] None.

2. Which of the following commands allows definition and assignment of environment variables under bash
a) env
b) export
c) environ
d) setenviron

View Answer

Answer: a [Reason:] None.

3. While executing a command, the shell
a) Executes it in the same process (as shell)
b) Creates a child shell to execute it
c) Loads a special program to take care of the execution
d) None of the mentioned

View Answer

Answer: b [Reason:] None.

4. Which variable contains current shell process id
a) $*
b) $?
c) $$
d) $!

View Answer

Answer: c [Reason:] None.

5. Which command is used to debug a shell script program
a) set
b) set -x
c) debug
d) db

View Answer

Answer: b [Reason:] None.

6. For every successful login, which script will be executed?
a) /etc/inittab
b) /etc/profile
c) /etc/login
d) /etc/init

View Answer

Answer: b [Reason:] None.

7. Hidden files are
a) Those whose ‘read’ bit is set to ‘h’
b) Permitted for (can be accessed) only superusers
c) Files that begin with a ‘.’
d) Files that cannot be opened by ordinary user for writing

View Answer

Answer: c [Reason:] None.

8. Shell is ?
a) Command Interpreter
b) Interface between Kernel and Hardware
c) Interface between user and applications
d) Command Compiler

View Answer

Answer: a [Reason:] None.

Linux MCQ Set 2

1. Which built-in command performs integer arithmetic in bash shell?
a) let
b) get
c) set
d) none of the mentioned

View Answer

Answer: a [Reason:] None.

2. Which expression use the value of the enclosed arithmetic expression?
a) $(())
b) $()
c) ${}
d) $[].

View Answer

Answer: a [Reason:] None.

3. If a and b are 2 variables then the meaning of a<<=b is
a) b = a << b
b) a = a << b
c) b = b << a
d) a = a << b

View Answer

Answer: b [Reason:] None.

4. Which one of the following is bitwise ‘exclusive or’ operator?
a) ^=
b) |=
c) !=
d) none of the mentioned

View Answer

Answer: a [Reason:] None.

5. Which one of the following is not a valid operator in bash shell?
a) ||
b) ~
c) =<<
d) -=

View Answer

Answer: c [Reason:] None.

6. What is the output of this program?

  1.    #!/bin/bash
  2.    a=2
  3.    b=4
  4.    let c=a**b
  5.    echo $c
  6.    exit 0

a) 8
b) 16
c) 32
d) none of the mentioned

View Answer

Answer: b [Reason:]’**’ is the exponentation operator in bash shell. Output: :/home/aidlo#./test.sh 16 :/home/aidlo#

7. What is the output of this program?

  1.    #!/bin/bash
  2.    a=10; b=20
  3.    c=$((++a))
  4.    let a=c+a
  5.    echo $a
  6.    exit 0

a) 21
b) 22
c) program will generate an error message
d) none of the mentioned

View Answer

Answer: b [Reason:] None. Output: :/home/aidlo#./test.sh 22 :/home/aidlo#

8. What is the output of this program?

  1.    #!/bin/bash
  2.    a=10
  3.    b=$(( $a<0?10:$a<100 ))
  4.    echo $b
  5.    exit 0

a) 10
b) 20
c) 1
d) 0

View Answer

Answer: c [Reason:] Firstly the ‘$a<0’ condition has been checked. Because it is false hence the right hand side condition of the colon (:) has been checked and this is true so program output is 1. Output: :/home/aidlo# ./test.sh 1 :/home/aidlo#

9. What is the output of this program?

  1.    #!/bin/bash
  2.    a=10
  3.    b=$(( $a<0&&$a<100 ))
  4.    echo $b
  5.    exit 0

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

View Answer

Answer: b [Reason:] The condition ‘$a<0’ is false so logical and operator provides the output 0. Output: :/home/aidlo# ./test.sh 0 :/home/aidlo#

10. What is the output of this program?

  1.     #!/bin/bash
  2.     a=1; b=2; c=3
  3.     d=$(( ++a**b*c++ + a ))
  4.     echo $d
  5.     exit 0

a) 14
b) 12
c) program will generate an error message
d) none of the mentioned

View Answer

Answer: a [Reason:] The operators in decreasing order of precedence are ++, **, *, +. Output: :/home/aidlo# ./test.sh 14 :/home/aidlo#

Linux MCQ Set 3

1. fc stands for
a) find command
b) fix command
c) both find & fix command
d) none of the mentioned

View Answer

Answer: c [Reason:]’fc -l’ is used to list history of commands and ‘fc -e’ to edit them and ‘history’ command also provides the histroy of commands.

2. Which command is used to reexecute the previous command?
a) !!
b) !cat
c) !3
d) !$

View Answer

Answer: a [Reason:]’!cat’ will reexecute the last cat command, ‘!3’ will reexecute the third last command and ‘!$’ will execute the last argument of previous command.

3. Which one of the following is not correct about job control in bash shell?
a) it is the ability to stop and resume any process running in shell at a later point
b) user employs this facility via an interactive interface supplied by the kernel’s terminal driver and bash
c) it is the ability to create any process
d) none of the mentioned

View Answer

Answer: c [Reason:] None.

4. Which command allows to view the current jobs being handled by the shell?
a) jobs
b) view
c) show
d) none of the mentioned

View Answer

Answer: a [Reason:] None.

5. What is job number?
a) same as PID
b) a unique number, assigned to each job in shell
c) same as PID and a unique number, assigned to each job in shell
d) none of the mentioned

View Answer

Answer: b [Reason:] None.

6. Ctrl-Z key combination
a) generates a SIGINT signal
b) stops the process running in the shell
c) kills the process running in the shell
d) generates a SIGINT signal & kills the process running in the shell

View Answer

Answer: b [Reason:] Ctrl-Z key combination generates a SIGTSTP signal and stops the process running in the shell.

7. Which command brings a background job into the foreground?
a) fg
b) bg
c) jobs %1
d) none of the mentioned

View Answer

Answer: a [Reason:] bg command brings a foreground job into the background.

8. ‘kill %s’ command will
a) terminate the job whose command line starts with s
b) terminate the last job
c) terminate the first job
d) none of the mentioned

View Answer

Answer: a [Reason:] None.

9. ‘stty tostop’ command will
a) stop all jobs running in the shell
b) stop background jobs if they try to send output to the terminal
c) this is not a valid command
d) none of the mentioned

View Answer

Answer: b [Reason:] None.

10. Which command terminates a running process by name of the process?
a) kill
b) pkill
c) killall
d) none of the mentioned

View Answer

Answer: c [Reason:] None.

Linux MCQ Set 4

1. What is the output of this program?

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

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

View Answer

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

[ aidlo]#

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("%dn",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 [Reason:] 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: [ aidlo]# gcc -o san san.c [ aidlo]# ./san 17654 [ aidlo]# 0

[ aidlo]#

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("%dn",getppid());
  16.                break;
  17.            default :
  18.                printf("%dn",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 [Reason:] 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: [ aidlo]# gcc -o san san.c [ aidlo]# ./san 17729 17729 [ aidlo]# ./san 17731 17731 [ aidlo]#

4. This program will print ____ as output.

  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("%dn",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 [Reason:] 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: [ aidlo]# gcc -o san san.c [ aidlo]# ./san [ aidlo]# 1

[ aidlo]#

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("%dn",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 [Reason:] 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: [ aidlo]# gcc -o san san.c [ aidlo]# ./san 10 [ aidlo]#

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("%dn",WEXITSTATUS(status));
  20.                    break;
  21.            }
  22.            return 0;
  23.    }

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

View Answer

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

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 [Reason:] The “execl” system call replaces the current process image with a new process image according to the arguments. Output: [ aidlo]# gcc -o san san.c [ aidlo]# ./san san san.c [ aidlo]#

8. How many time “Aidlo” 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("Aidlon");
  12.        return 0;
  13.    }

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

View Answer

Answer: a [Reason:] 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: [ aidlo]# gcc -o san san.c [ aidlo]# ./san san san.c [ aidlo]#

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("Aidlon");
  10.        return 0;
  11.    }

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

View Answer

Answer: c [Reason:] None. Output: [ aidlo]# gcc -o san san.c [ aidlo]# ./san Aidlo [ aidlo]# Aidlo Aidlo Aidlo Aidlo Aidlo Aidlo Aidlo

[ aidlo]#

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("%dn",a);
  14.         } 
  15.         return 0;
  16.     }

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

View Answer

Answer: b [Reason:] None. Output: [ aidlo]# gcc -o san san.c [ aidlo]# ./san 30 [ aidlo]#

Linux MCQ Set 5

1. What is the output of this program?

  1.    #include<stdio.h>
  2.    #include<sys/types.h>
  3.    #include<sys/socket.h>
  4.  
  5.    int main()
  6.    {
  7.        struct sockaddr_in addr;
  8.        int fd;
  9.        fd = socket(AF_INET,SOCK_STREAM,0);
  10.        printf("%dn",fd);
  11.        return 0;
  12.    }

a) -1
b) 3
c) error
d) none of the mentioned

View Answer

Answer: c [Reason:] The header file netinet/in.h is required to use the structure sockaddr_in. Output: [ aidlo]# gcc -o san san.c san.c: In function ‘main’: san.c:7:21: error: storage size of ‘addr’ isn’t known [ aidlo]#

2. What is the output of this program?

  1.    #include<stdio.h>
  2.    #include<stdlib.h>
  3.    #include<netinet/in.h>
  4.    #include<sys/types.h>
  5.    #include<sys/socket.h>
  6.  
  7.    int main()
  8.    {
  9.        int fd_server, fd_client, len, len_client;
  10.        struct sockaddr_in add_server, add_client;
  11.        char buff[10];
  12.        fd_server = socket(AF_INET,SOCK_STREAM,0);
  13.        if (fd_server == -1)
  14.        {
  15.            perror("fd_sock");
  16.            exit(1);   
  17.        }
  18.        len = sizeof(add_server);
  19.        len_client = sizeof(add_client);
  20.        if( bind(fd_server,(struct sockaddr*)&add_server,len) != 0)
  21.            perror("bind");
  22.        fd_client = accept(fd_server,(struct sockaddr*)&add_client,len_client);
  23.        if(fd_client == -1)
  24.            perror("accept");
  25.        read(fd_client,buff,10);
  26.        return 0;
  27.    }

a) segmentation fault
b) error at the time of compilation
c) syntax error
d) none of the mentioned

View Answer

Answer: b [Reason:] The third argument of the accept is the type of pointer. Output: [ aidlo]# gcc -o san san.c san.c: In function ‘main’: san.c:26:39: warning: passing argument 3 of ‘accept’ makes pointer from integer without a cast [enabled by default] /usr/include/sys/socket.h:214:12: note: expected ‘socklen_t * __restrict__’ but argument is of type ‘int’ [ aidlo]#

3. This program can send the request to

  1.    #include<stdio.h>
  2.    #include<netinet/in.h>
  3.    #include<sys/types.h>
  4.    #include<sys/socket.h>
  5.  
  6.    int main()
  7.    {
  8.        int fd_client,fd, len;
  9.        struct sockaddr_in add_server;
  10.        fd_client = socket(AF_INET,SOCK_STREAM,0);
  11.        if (fd_client == -1)
  12.        {
  13.            perror("fd_sock");
  14.            exit(1);
  15.        }
  16.        add_server.sin_family = AF_INET;
  17.        add_server.sin_port = ntohs(4001);
  18.        add_server.sin_addr.s_addr = inet_addr("193.39.0.4");
  19.        len = sizeof(add_server);
  20.        fd  = connect(fd_client,(struct sockaddr*)&add_server,len);
  21.        if(fd == -1)
  22.            perror("connect");
  23.        return 0;
  24.    }

a) the system having IP address 193.39.0.4
b) any system present in the network
c) any system of the private network
d) none of the mentioned

View Answer

Answer: a [Reason:] The IP address is mentioned in the proper element of the structure sockaddr_in

4. This program is valid for

  1.    #include<stdio.h>
  2.    #include<netinet/in.h>
  3.    #include<sys/types.h>
  4.    #include<sys/socket.h>
  5.  
  6.    int main()
  7.    {
  8.        int fd_client,fd, len;
  9.        struct sockaddr_in add_server;
  10.        fd_client = socket(AF_INET,SOCK_STREAM,0);
  11.        if (fd_client == -1)
  12.        {
  13.            perror("fd_sock");
  14.            exit(1);
  15.        }
  16.        add_server.sin_family = AF_INET;
  17.        add_server.sin_port = ntohs(4001);
  18.        add_server.sin_addr.s_addr = inet_addr("144.29.8.2");
  19.        len = sizeof(add_server);
  20.        fd  = connect(fd_client,(struct sockaddr*)&add_server,len);
  21.        return 0;
  22.    }

a) IPv4
b) IPv6
c) both IPv4 and IPv6
d) none of the mentioned

View Answer

Answer: a [Reason:] None.

5. What is the output of this program?

  1.    #include<stdio.h>
  2.    #include<sys/socket.h>
  3.    int main()
  4.    { 
  5.        int ret;
  6.        ret = shutdown(0,0);
  7.        printf("%dn",ret);
  8.        return 0;
  9.    }

a) 0
b) -1
c) can not be determined
d) none of the mentioned

View Answer

Answer: b [Reason:] The shutdown() is used to close a socket and the first argument in shutdown() is socket. Output: [ aidlo]# gcc -o san san.c [ aidlo]# ./san -1 [ aidlo]#

6. What is the problem with this server program?

  1.    #include<stdio.h>
  2.    #include<stdlib.h>
  3.    #include<netinet/in.h>
  4.    #include<sys/types.h>
  5.    #include<sys/socket.h>
  6.  
  7.    int main()
  8.    {
  9.        int fd_server, fd_client, len;
  10.        struct sockaddr_in add_server;
  11.        fd_server = socket(AF_INET,SOCK_STREAM,0);
  12.        if (fd_server == -1)
  13.        {
  14.            perror("fd_sock");
  15.            exit(1);
  16.        }
  17.        add_server.sin_family = AF_INET;
  18.        add_server.sin_port = htons(4001);
  19.        add_server.sin_addr.s_addr = inet_addr("122.23.1.1");
  20.        len = sizeof(add_server);
  21.        if( bind(fd_server,(struct sockaddr*)&add_server,len) != 0)
  22.            perror("bind");
  23.        if(listen(fd_server,5) != 0)
  24.            perror("listen");
  25.        fd_client = accept(fd_server,(struct sockaddr*)&add_server,&len);
  26.        if(fd_client == -1)
  27.            perror("accept");
  28.        return 0;
  29.    }

a) it can not accept the request of any client
b) it will give the segmentation fault
c) there is no problem with this program
d) none of the mentioned

View Answer

Answer: a [Reason:] The address format of the client must match in the server.

7. What is the output of this program?

  1.    #include<stdio.h>
  2.    #include<stdlib.h>
  3.    #include<netinet/in.h>
  4.    #include<sys/types.h>
  5.    #include<sys/socket.h>
  6.  
  7.    int main()
  8.    {
  9.        int fd_server, fd_client, len, len_client;
  10.        struct sockaddr_in add_server;
  11.        fd_server = socket(AF_INET,SOCK_STREAM,0);
  12.        fd_client = accept(fd_server,(struct sockaddr*)&add_server,&len);
  13.        if(fd_client == -1)
  14.            perror("accept");
  15.        if(listen(fd_server,5) != 0)
  16.            perror("listen");
  17.        return 0;
  18.    }

a) syntax error
b) error at the time of compilation
c) segmentation fault
d) none of the mentioned

View Answer

Answer: d [Reason:] The listen() must always be used before accept(). Output: [ aidlo]# gcc -o san san.c [ aidlo]# ./san accept: Invalid argument [ aidlo]#

8. What is the output of this program?

  1.    #include<stdio.h>
  2.    #include<stdlib.h>
  3.    #include<netinet/in.h>
  4.    #include<sys/types.h>
  5.    #include<sys/socket.h>
  6.  
  7.    int main()
  8.    {
  9.        int fd_server, fd_client, len, len_client;
  10.        struct sockaddr_in add_server;
  11.        fd_server = socket(AF_INET,SOCK_STREAM,0);
  12.        close(fd_server);
  13.            perror("accept");
  14.        if(listen(fd_server,5) != 0)
  15.            perror("listen");
  16.        fd_client = accept(fd_server,(struct sockaddr*)&add_server,&len);
  17.            if(fd_client == -1)
  18.        return 0;
  19.    }

a) syntax error
b) error at the time of compilation
c) segmentation fault
d) none of the mentioned

View Answer

Answer: d [Reason:] The program will not work properly because the file descriptor is not available in the for listen() and accept(). Output: [ aidlo]# gcc -o san san.c [ aidlo]# ./san accept: Success listen: Bad file descriptor [ aidlo]#

9. On which system call, this program (process) waits until the server responds?

  1.    #include<stdio.h>
  2.    #include<netinet/in.h>
  3.    #include<sys/types.h>
  4.    #include<sys/socket.h>
  5.  
  6.    int main()
  7.    {
  8.        int fd_client,fd, len;
  9.        struct sockaddr_in add_server;
  10.        fd_client = socket(AF_INET,SOCK_STREAM,0);
  11.        if (fd_client == -1){
  12.            perror("fd_sock");
  13.            exit(1);
  14.    }
  15.    add_server.sin_family = AF_INET;
  16.    add_server.sin_port = ntohs(4001);
  17.    add_server.sin_addr.s_addr = inet_addr("127.0.0.1");
  18.    len = sizeof(add_server);
  19.    fd  = connect(fd_client,(struct sockaddr*)&add_server,len);
  20.    if(fd == -1)
  21.        perror("connect");
  22.        write(fd,"Hellon",6);
  23.        return 0;
  24.    }

a) socket()
b) connect()
c) both socket() and connect()
d) none of the mentioned

View Answer

Answer: a [Reason:] None.

10. What is the the response of this server for this client if both programs are running on the same system?

  1.    /*This is server.c*/ 
  2.    #include<stdio.h>
  3.    #include<stdlib.h>
  4.    #include<netinet/in.h>
  5.    #include<sys/types.h>
  6.    #include<sys/socket.h>
  7.  
  8.    int main()
  9.    {
  10.        int fd_server, fd_client, len, len_client;
  11.        struct sockaddr_in add_server, add_client;
  12.        char buff[10];
  13.        fd_server = socket(AF_INET,SOCK_STREAM,0);
  14.        if (fd_server == -1)
  15.        {
  16.            perror("fd_sock");
  17.            exit(1);
  18.        }
  19.       add_server.sin_family = AF_INET;
  20.       add_server.sin_port = htons(4001);
  21.       add_server.sin_addr.s_addr = inet_addr("127.0.0.1");
  22.       len = sizeof(add_server);
  23.       len = sizeof(add_client);
  24.       if( bind(fd_server,(struct sockaddr*)&add_server,len) != 0)
  25.        perror("bind");
  26.        if(listen(fd_server,5) != 0)
  27.            perror("listen");
  28.        fd_client = accept(fd_server,(struct sockaddr*)&add_client,&len_client);
  29.        if(fd_client == -1)
  30.            perror("accept");
  31.        read(fd_client,buff,10);
  32.        return 0;
  33.    }
  34.    /*This is the client.c*/
  35.    #include<stdio.h>
  36.    #include<netinet/in.h>
  37.    #include<sys/types.h>
  38.    #include<sys/socket.h>
  39.  
  40.    int main()
  41.    {
  42.        int fd_client,fd, len;
  43.        struct sockaddr_in add_server;
  44.        fd_client = socket(AF_INET,SOCK_STREAM,0);
  45.        if (fd_client == -1)
  46.        {
  47.            perror("fd_sock");
  48.            exit(1);
  49.        }
  50.        add_server.sin_family = AF_INET;
  51.        add_server.sin_port = ntohs(4001);
  52.        add_server.sin_addr.s_addr = inet_addr("127.0.0.1");
  53.        len = sizeof(add_server);
  54.        fd  = connect(fd_client,(struct sockaddr*)&add_server,len);
  55.        if(fd == -1)
  56.        perror("connect");
  57.        write(fd,"Hellon",6);
  58.        return 0;
  59.    }

a) the server will write back to the client whatever the clinet will write to the server
b) the client server communication will not work
c) the response can not be determined
d) none of the mentioned

View Answer

Answer: a [Reason:] The loopback address is used as IP address in both the programs.