Recently Updated Linux Debugging Interview Questions
Q – 1 Which one of the following command saves the command history of GDB in a file?
a) history
b) set history
c) set history save on
d) none of the mentioned
Ans- c) set history save on
Q – 2 In GDB, a trace-point can be set by the command
a) trace
b) set
c) break trace
d) none of the mentioned
Ans- a) trace
Q – 3 The command “show commands” of GDB
a) displays the last 10 commands in the command history
b) displays all commands of the command history
c) displays all the commands available in GDB
d) none of the mentioned
Ans- a) displays the last 10 commands in the command history
Q – 4 The GDB command “show output-radix”
a) sets the default base for numeric display
b) displays the current default base for numeric display
c) both (a) and (b)
d) none of the mentioned
Ans- b) displays the current default base for numeric display
Q – 5 The user can define a command for GDB with the command:
a) define
b) command
c) assign
d) none of the mentioned
Ans- a) define
Q – 6 By default the GDB automatically executes the command from its:
a) init files
b) start files
c) begin files
d) none of the mentioned
Ans- a) init files
Q – 7 The GDB text user interface uses the ____ library to show the source file.
a) curses
b) YUI
c) JUI
d) none of the mentioned
Ans- a) curses
Q – 8 Which one of the following GDB command allows to move from one stack frame to another without printing the frame?
a) select-frame
b) frame
c) frame move
d) none of the mentioned
Ans- a) select-frame
Q – 9 Which one of the following GDB command deletes any break-point at the next instruction to be executed in the selected stack frame?
a) clear
b) delete
c) disable
d) none of the mentioned
Ans- a) clear
Q – 10 The result of an expression can be assigned to an environment variable with the command:
a) assign
b) set
c) env
d) none of the mentioned
Ans- b) set
Q – 11 In GDB hardware-dependent information about the floating point unit can be displayed by the command
a) info float
b) display float
c) show float
d) none of the mentioned
Ans- a) info float
Q – 13 Which one of the following variables is used within GDB to hold on to a value and refer to it later?
a) convenience variables
b) environment variables
c) temporary variables
d) none of the mentioned
Ans- a) convenience variables
Q – 14 If we want to print the value of a variable in hexadecimal, we have to use “print” command with the option ___ in GDB.
a) x
b) h
c) hex
d) none of the mentioned
Ans- a) x
Q – 16 With the list command, by default GDB prints the ____ source lines.
a) 20
b) 10
c) all
d) none of the mentioned
Ans- b) 10
Q – 17 Which one of the following is a special breakpoint that stops the program when the value of an expression changes in GDB?
a) watchpoint
b) catchpoint
c) getpoint
d) none of the mentioned
Ans- a) watchpoint
Q – 18 Inside GDB, a program may stop because of
a) a signal
b) a breakpoint
c) step command
d) all of the mentioned
Ans- d) all of the mentioned
Q – 19 While debugging with GDB, arguments to the program can be specified by the arguments of _____ command.
a) run
b) gdb
c) make
d) none of the mentioned
Ans- a) run
Q – 20 What is the output of this program no 16?
#include
#include<sys/types.h>
#include<netinet/in.h>
#include<sys/socket.h>
#include
int main()
{
struct sockaddr_in addr;
int fd;
fd = socket(AF_UNIX,SOCK_STREAM,0);
if (fd == -1)
perror(“socket”);
addr.sun_family = AF_UNIX;
strcpy(addr.sun_path,”san_sock”);
if (bind(4,(struct sockaddr*)&addr,sizeof(addr)) == -1)
printf(“Sanfoudnryn”);
return 0;
}
a) error
b) “google”
c) segmentation fault
d) none of the mentioned
Ans- a) error
Q – 21 What is the output of this program no 15?
#include
#include<sys/types.h>
#include<sys/un.h>
#include<sys/socket.h>
int main()
{
struct sockaddr_un add_server, add_client;
int fd_server, fd_client;
int len;
char ch;
fd_server = socket(AF_UNIX,SOCK_STREAM,0);
if(fd_server == -1)
perror(“socket”);
add_server.sun_family = AF_UNIX;
strcpy(add_server.sun_path,”san_sock”);
if( bind(fd_server,(struct sockaddr*)&add_server,sizeof(add_server)) != 0)
perror(“bind”);
len = sizeof(add_client);
fd_client = connect(fd_server,(struct sockaddr*)&add_client,&len);
printf(“googlen”);
return 0;
}
a) this program will print the string “google”
b) segmentation fault
c) error
d) none of the mentioned
Ans- c) error
Q – 22 What this program is not able to connect with any client program?
#include
#include<sys/types.h>
#include<sys/un.h>
#include<sys/socket.h>
int main()
{
struct sockaddr_un add_server, add_client;
int fd_server, fd_client;
int len;
char ch;
fd_server = socket(AF_UNIX,SOCK_STREAM,0);
if(fd_server == -1)
perror(“socket”);
add_server.sun_family = AF_UNIX;
strcpy(add_server.sun_path,”san_sock”);
if( bind(fd_server,(struct sockaddr*)&add_server,sizeof(add_server)) != 0)
perror(“bind”);
len = sizeof(add_client);
fd_client = accept(fd_server,(struct sockaddr*)&add_client,&len);
printf(“googlen”);
return 0;
}
a) the listen() is missing
b) the connect() is missing
c) the read() and write() are missing
d) none of the mentioned
Ans- a) the listen() is missing
Q – 23 What is the output of this program no 14?
#include
#include<sys/types.h>
#include<sys/un.h>
#include<sys/socket.h>
#include
int main()
{
struct sockaddr_un addr;
int fd;
fd = socket(AF_UNIX,SOCK_STREAM,0);
if (fd == -1)
perror(“socket”);
addr.sun_family = AF_UNIX;
strcpy(addr.sun_path,”san_sock”);
if (bind(4,(struct sockaddr*)&addr,sizeof(addr)) == -1)
printf(“Sanfoudnryn”);
return 0;
}
a) this program will print the string “google”
b) this program will not print the string “google”
c) segmentation fault
d) none of the mentioned
Ans- a) this program will print the string “google”
Q – 24 What is the output of this program?
#include
#include<sys/types.h>
#include<sys/socket.h>
int main()
{
int fd;
fd = socket(AF_UNIX,SOCK_STREAM,0);
printf(“%dn”,fd);
return 0;
}
a) 0
b) 1
c) 2
d) 3
Ans- d) 3
Q – 25 What is the output of the program no 13?
#include
#include<sys/types.h>
#include<sys/un.h>
#include<sys/socket.h>
int main()
{
struct sockaddr_un add_server, add_client;
int fd_server, fd_client;
int len;
char ch;
fd_server = socket(AF_UNIX,SOCK_STREAM,0);
if(fd_server == -1)
perror(“socket”);
add_server.sun_family = AF_UNIX;
strcpy(add_server.sun_path,”san_sock”);
if( bind(fd_server,(struct sockaddr*)&add_server,sizeof(add_server)) != 0)
perror(“bind”);
if( listen(fd_server,3) != 0)
perror(“listen”);
len = sizeof(add_client);
fd_client = accept(fd_server,(struct sockaddr*)&add_client,&len);
printf(“googlen”);
return 0;
}
a) the program will print the string “google”
b) the process will remain block
c) segmentation fault
d) none of the mentioned
Ans- b) the process will remain block
Q – 26 What is the length of of the queue for pending connections in this program?
#include
#include<sys/types.h>
#include<sys/un.h>
#include<sys/socket.h>
int main()
{
struct sockaddr_un add_server;
int fd_server;
fd_server = socket(AF_UNIX,SOCK_STREAM,0);
if(fd_server == -1)
perror(“socket”);
add_server.sun_family = AF_UNIX;
strcpy(add_server.sun_path,”server_sock2″);
if( bind(fd_server,(struct sockaddr*)&add_server,sizeof(add_server)) != 0)
perror(“bind”);
if( listen(fd_server,3) != 0)
perror(“listen”);
return 0;
}
a) 0
b) 1
c) 2
d) 3
Ans- d) 3
Q – 27 By this program the soket “san_sock” will create
#include
#include<sys/types.h>
#include<sys/un.h>
#include<sys/socket.h>
int main()
{
struct sockaddr_un add_server;
int fd_server;
fd_server = socket(AF_UNIX,SOCK_STREAM,0);
if(fd_server == -1)
perror(“socket”);
add_server.sun_family = AF_UNIX;
strcpy(add_server.sun_path,”san_sock”);
if( bind(fd_server,(struct sockaddr*)&add_server,sizeof(add_server)) != 0)
perror(“bind”);
return 0;
}
a) in the /tmp directory
b) in the /usr directory
c) in the present working directory
d) none of the mentioned
Ans- c) in the present working directory
Q – 28 In this program, the third argument of the socket() is used for _____ potocol.
#include
#include<sys/types.h>
#include<sys/socket.h>
int main()
{
int fd_socket;
if(socket(AF_UNIX,SOCK_STREAM,0) == -1)
perror(“socket”);
return 0;
}
a) TCP/IP
b) UDP
c) both (a) and (b)
d) none of mentioned
Ans- a) TCP/IP
Q – 29 What is the output of this program no 12?
#include
int main()
{
int fd_socket;
fd_socket = socket(AF_UNIX,SOCK_STREAM,0);
printf(“%dn”,fd_socket);
return 0;
}
a) -1
b) 0
c) any integer value
d) none of the mentioned
Ans- d) none of the mentioned
Q – 30 What is the the response of this server for this client if both programs are running on the same system?
/*This is server.c*/
#include
#include
#include<netinet/in.h>
#include<sys/types.h>
#include<sys/socket.h>
int main()
{
int fd_server, fd_client, len, len_client;
struct sockaddr_in add_server, add_client;
char buff[10];
fd_server = socket(AF_INET,SOCK_STREAM,0);
if (fd_server == -1){
perror(“fd_sock”);
exit(1);
}
add_server.sin_family = AF_INET;
add_server.sin_port = htons(4001);
add_server.sin_addr.s_addr = inet_addr(“127.0.0.1”);
len = sizeof(add_server);
len = sizeof(add_client);
if( bind(fd_server,(struct sockaddr*)&add_server,len) != 0)
perror(“bind”);
if(listen(fd_server,5) != 0)
perror(“listen”);
fd_client = accept(fd_server,(struct sockaddr*)&add_client,&len_client);
if(fd_client == -1)
perror(“accept”);
read(fd_client,buff,10);
return 0;
}
/*This is the client.c*/
#include
#include<netinet/in.h>
#include<sys/types.h>
#include<sys/socket.h>
int main()
{
int fd_client,fd, len;
struct sockaddr_in add_server;
fd_client = socket(AF_INET,SOCK_STREAM,0);
if (fd_client == -1){
perror(“fd_sock”);
exit(1);
}
add_server.sin_family = AF_INET;
add_server.sin_port = ntohs(4001);
add_server.sin_addr.s_addr = inet_addr(“127.0.0.1”);
len = sizeof(add_server);
fd = connect(fd_client,(struct sockaddr*)&add_server,len);
if(fd == -1)
perror(“connect”);
write(fd,”Hellon”,6);
return 0;
}
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
Ans- a) the server will write back to the client whatever the client will write to the server
Q – 31 On which system call, this program (process) waits until the server responds?
#include
#include<netinet/in.h>
#include<sys/types.h>
#include<sys/socket.h>
int main()
{
int fd_client,fd, len;
struct sockaddr_in add_server;
fd_client = socket(AF_INET,SOCK_STREAM,0);
if (fd_client == -1){
perror(“fd_sock”);
exit(1);
}
add_server.sin_family = AF_INET;
add_server.sin_port = ntohs(4001);
add_server.sin_addr.s_addr = inet_addr(“127.0.0.1”);
len = sizeof(add_server);
fd = connect(fd_client,(struct sockaddr*)&add_server,len);
if(fd == -1)
perror(“connect”);
write(fd,”Hellon”,6);
return 0;
}
a) socket()
b) connect()
c) both (a) and (b)
d) none of the mentioned
Ans- a) socket()
Q – 32 What is the output of this program no 11?
#include
#include
#include<netinet/in.h>
#include<sys/types.h>
#include<sys/socket.h>
int main()
{
int fd_server, fd_client, len, len_client;
struct sockaddr_in add_server;
fd_server = socket(AF_INET,SOCK_STREAM,0);
close(fd_server);
perror(“accept”);
if(listen(fd_server,5) != 0)
perror(“listen”);
fd_client = accept(fd_server,(struct sockaddr*)&add_server,&len);
if(fd_client == -1)
return 0;
}
a) syntax error
b) error at the time of compilation
c) segmentation fault
d) none of the mentioned
Ans- d) none of the mentioned
Q – 33 What is the output of this program no 10?
#include
#include
#include<netinet/in.h>
#include<sys/types.h>
#include<sys/socket.h>
int main()
{
int fd_server, fd_client, len, len_client;
struct sockaddr_in add_server;
fd_server = socket(AF_INET,SOCK_STREAM,0);
fd_client = accept(fd_server,(struct sockaddr*)&add_server,&len);
if(fd_client == -1)
perror(“accept”);
if(listen(fd_server,5) != 0)
perror(“listen”);
return 0;
}
a) syntax error
b) error at the time of compilation
c) segmentation fault
d) none of the mentioned
Ans- d) none of the mentioned
Q – 34 What is the problem with this server program?
#include
#include
#include<netinet/in.h>
#include<sys/types.h>
#include<sys/socket.h>
int main()
{
int fd_server, fd_client, len;
struct sockaddr_in add_server;
fd_server = socket(AF_INET,SOCK_STREAM,0);
if (fd_server == -1){
perror(“fd_sock”);
exit(1);
}
add_server.sin_family = AF_INET;
add_server.sin_port = htons(4001);
add_server.sin_addr.s_addr = inet_addr(“122.23.1.1”);
len = sizeof(add_server);
if( bind(fd_server,(struct sockaddr*)&add_server,len) != 0)
perror(“bind”);
if(listen(fd_server,5) != 0)
perror(“listen”);
fd_client = accept(fd_server,(struct sockaddr*)&add_server,&len);
if(fd_client == -1)
perror(“accept”);
return 0;
}
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
Ans- a) it can not accept the request of any client
Q – 35 What is the output of this program?
#include
#include<sys/socket.h>
int main()
{
int ret;
ret = shutdown(0,0);
printf(“%dn”,ret);
return 0;
}
a) 0
b) -1
c) can not be determined
d) none of the mentioned
Ans- b) -1
Q – 36 This program is valid for
#include
#include<netinet/in.h>
#include<sys/types.h>
#include<sys/socket.h>
int main()
{
int fd_client,fd, len;
struct sockaddr_in add_server;
fd_client = socket(AF_INET,SOCK_STREAM,0);
if (fd_client == -1){
perror(“fd_sock”);
exit(1);
}
add_server.sin_family = AF_INET;
add_server.sin_port = ntohs(4001);
add_server.sin_addr.s_addr = inet_addr(“144.29.8.2”);
len = sizeof(add_server);
fd = connect(fd_client,(struct sockaddr*)&add_server,len);
return 0;
}
a) IPv4
b) IPv6
c) both (a) and (b)
d) none of the mentioned
Ans- a) IPv4
Q – 37 This program can send the request to
#include
#include<netinet/in.h>
#include<sys/types.h>
#include<sys/socket.h>
int main()
{
int fd_client,fd, len;
struct sockaddr_in add_server;
fd_client = socket(AF_INET,SOCK_STREAM,0);
if (fd_client == -1){
perror(“fd_sock”);
exit(1);
}
add_server.sin_family = AF_INET;
add_server.sin_port = ntohs(4001);
add_server.sin_addr.s_addr = inet_addr(“193.39.0.4”);
len = sizeof(add_server);
fd = connect(fd_client,(struct sockaddr*)&add_server,len);
if(fd == -1)
perror(“connect”);
return 0;
}
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
Ans- a) the system having IP address 193.39.0.4
Q – 38 What is the output of this program?
#include
#include
#include<netinet/in.h>
#include<sys/types.h>
#include<sys/socket.h>
int main()
{
int fd_server, fd_client, len, len_client;
struct sockaddr_in add_server, add_client;
char buff[10];
fd_server = socket(AF_INET,SOCK_STREAM,0);
if (fd_server == -1){
perror(“fd_sock”);
exit(1);
}
len = sizeof(add_server);
len_client = sizeof(add_client);
if( bind(fd_server,(struct sockaddr*)&add_server,len) != 0)
perror(“bind”);
fd_client = accept(fd_server,(struct sockaddr*)&add_client,len_client);
if(fd_client == -1)
perror(“accept”);
read(fd_client,buff,10);
return 0;
}
a) segmentation fault
b) error at the time of compilation
c) syntax error
d) none of the mentioned
Ans- b) error at the time of compilation
Q – 39 What is the output of this program no 9?
#include
#include<sys/types.h>
#include<sys/socket.h>
int main()
{
struct sockaddr_in addr;
int fd;
fd = socket(AF_INET,SOCK_STREAM,0);
printf(“%dn”,fd);
return 0;
}
a) -1
b) 3
c) error
d) none of the mentioned
Ans- c) error
Q – 40 The execution of the program in GDB can be affected by:
a) arguments
b) working directory
c) environment
d) all of the mentioned
Ans- d) all of the mentioned
Q – 41 Assemble code of the program can be displayed in GDB by the command:
a) disassemble
b) assemble
c) assembly
d) none of the mentioned
Ans- a) disassemble
Q – 42 Which one of the following is not true about the GDB?
a) info register is used to see that what is in the processor registers
b) processor registers can not be accessed by GDB
c) first 32 bits of the variable can not be examined
d) none of the mentioned
Ans- c) first 32 bits of the variable can not be examined
Q – 43 Which GDB command is used to examine the memory?
a) x
b) y
c) z
d) none of the mentioned
Ans- a) x
Q – 44 In GDB breakpoints can be skipped by the command:
a) ignore
b) reject
c) skip
d) none of the mentioned
Ans- a) ignore
Q – 45 What is temporary breakpoint?
a) it stops the program once
b) it is removed after one execution of the program
c) both (a) and (b)
d) none of the mentioned
Ans- c) both (a) and (b)
Q – 46 If we have multiple source files, then during the debugging with GDB:
a) breakpoint can not be set
b) break point can be set by “break” command with a filename
c) break point can be set only to makefile
d) none of the mentioned
Ans- b) break point can be set by “break” command with a filename
Q – 47 The GDB command “info local”
a) displays the list of local variables
b) value of local values for the current stack frame
c) both (a) and (b)
d) none of the mentioned
Ans- c) both (a) and (b)
Q – 48 GDB command “frame” is used:
a) to change the stack frames
b) to check the stack frames only
c) it is not a valid command
d) none of the mentioned
Ans- a) to change the stack frames
Q – 49 While debugging with GDB:
a) variables can be print
b) variables can be modify
c) both (a) and (b)
d) none of the mentioned
Ans- c) both (a) and (b)
Q – 50 Which one of the following is not true about GDB?
a) quit command is used to exit the GDB
b) kill command is used to stop execution in GDB
c) if the execution is stopped by kill command then it can not be started again
d) none of the mentioned
Ans- c) if the execution is stopped by kill command then it can not be started again
Q – 51 We can list all the break-point in GDB by the command:
a) info break
b) break all
c) both (a) and (b)
d) none of the mentioned
Ans- a) info break
Q – 52 To put the breakpoint at the current line ____ command can be used?
a) b
b) break
c) both (a) and (b)
d) none of the mentioned
Ans- c) both (a) and (b)
Q – 53 Which GDB command can be used to put a break-point at the beginning of the program?
a) b main
b) b start
c) break
d) none of the mentioned
Ans- a) b main
Q – 54 GDB can be used:
a) to find out the memory leakages
b) to get the result of a particular expression in a program
c) to find the reason of segementation fault
d) all of the mentioned
Ans- d) all of the mentioned
Q – 55 Which GDB command reloads the debugging information?
a) file
b) reload
c) debug
d) none of the mentioned
Ans- a) file
Q – 56 The “step” command of GDB:
a) executes the current line of the program
b) stops the next statement to be executed
c) both (a) and (b)
d) none of the mentioned
Ans- c) both (a) and (b)
Q – 57 The specific break point can be deleted by _____ command in GDB.
a) delete
b) del
c) remove
d) none of the mentioned
Ans- a) delete
Q – 58 Which GDB command produces a stack trace of the function calls that lead to a segmentation fault?
a) trace
b) backtrace
c) forwardtrace
d) none of the mentioned
Ans- b) backtrace
Q – 59 Which GDB command interrupts the program whenever the value of a variable is modified and prints the value old and new values of the variable?
a) watch
b) show
c) trace
d) none of the mentioned
Ans- a) watch
Q – 60 Which GDB command prints the value of a variable in hex.
a) print/x
b) print/h
c) print/e
d) none of the mentioned
Ans- a) print/x
Q – 61 To print the value of a variable while debugging with GDB, ______ command can be used.
a) printf
b) print
c) show
d) none of the mentioned
Ans- b) print
Q – 62 At the time of debugging with GDB, if we just press ENTER:
a) GDB will repeat the same command you just gave it
b) GDB will do nothing
c) GDB will exit
d) none of the mentioned
Ans- a) GDB will repeat the same command you just gave it
Q – 63 In GDB debugging, we can proceed to the next break-point with command:
a) next
b) continue
c) both (a) and (b)
d) none of the mentioned
Ans- b) continue
Q – 64 In debugging with GDB, break points can be set to:
a) any line
b) any function
c) both (a) and (b)
d) none of the mentioned
Ans- c) both (a) and (b)
Q – 65 The command “gdb google”
a) will start debugging for the file “google” if the file is compiled with -g option with GCC
b) will create executable for debugging
c) will provide all errors present in the file “google”
d) none of the mentioned
Ans- a) will start debugging for the file “google” if the file is compiled with -g option with GCC
Q – 66 GDB can be used for:
a) c language
b) c++ language
c) both (a) and (b)
d) none of the mentioned
Ans- c) both (a) and (b)
Q – 67 GDB stands for:
a) GNU debugger
b) general debugging breakpoint
c) general debugger
d) none of the mentioned
Ans- a) GNU debugger
Q – 68 In GDB, breakpoints can be set by the command:
a) break
b) b
c) both (a) and (b)
d) none of the mentioned
Ans- c) both (a) and (b)
Q – 69 For debugging with GDB, the compiled program can be run by the command
a) run
b) execute
c) ./
d) none of the mentioned
Ans- a) run
Q – 70 For debugging with GDB, the file “google” can be created with the command:
a) gcc -g -o google google.c
b) gcc -g google.c
c) gdb google
d) none of the mentioned
Ans- a) gcc -g -o google google.c
Q – 71 What is the output of this program no 8?
#include
#include
void *fun_t(void *arg);
void *fun_t(void *arg)
{
sleep(1);
}
int main()
{
pthread_t pt;
void *res_t;
if(pthread_create(&pt,NULL,fun_t,NULL) != 0)
perror(“pthread_create”);
if(pthread_join(pt,&res_t) != 0)
perror(“pthread_join”);
printf(“%sn”,res_t);
return 0;
}
a) this process will pause
b) segmentation fault
c) run time error
d) none of the mentioned
Ans- b) segmentation fault
Q – 72 What is the output of this program no 7?
#include
#include #include
void *fun_t(void *arg);
void *fun_t(void *arg)
{
pthread_exit(“Bye”);
printf(“googlen”);
}
int main()
{
pthread_t pt;
void *res_t;
if(pthread_create(&pt,NULL,fun_t,NULL) != 0)
perror(“pthread_create”);
if(pthread_join(pt,&res_t) != 0)
perror(“pthread_join”);
printf(“%sn”,res_t);
return 0;
}
a) google
b) Bye
c) segementation fault
d) run time error
Ans- b) Bye
Q – 73 What is the output of this program no 6?
#include
#include #include
int fd;
void *fun_t(void *arg);
void *fun_t(void *arg)
{
char buff[10];
int count;
count = read(fd,buff,10);
printf(“%dn”,count);
pthread_exit(“Bye”);
}
int main()
{
pthread_t pt;
void *res_t;
fd = open(“san.c”,O_RDONLY);
if(pthread_create(&pt,NULL,fun_t,NULL) != 0)
perror(“pthread_create”);
if(pthread_join(pt,&res_t) != 0)
perror(“pthread_join”);
return 0;
}
a) 10
b) 0
c) -1
d) segmentation fault
Ans- a) 10
Q – 74 Which one of the following statement is not true about this program?
#include
#include
void *fun_t(void *arg);
void *fun_t(void *arg)
{
printf(“%dn”,getpid());
pthread_exit(“Bye”);
}
int main()
{
pthread_t pt;
void *res_t;
if(pthread_create(&pt,NULL,fun_t,NULL) != 0)
perror(“pthread_create”);
if(pthread_join(pt,&res_t) != 0)
perror(“pthread_join”);
printf(“%dn”,getpid());
return 0;
}
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
Ans- a) both printf statements will print the same value
Q – 75 What is the output of this program no 4?
#include
#include
int a;
void *fun_t(void *arg);
void *fun_t(void *arg)
{
a = 20;
pthread_exit(“Bye”);
}
int main()
{
pthread_t pt;
void *res_t;
a = 10;
if(pthread_create(&pt,NULL,fun_t,NULL) != 0)
perror(“pthread_create”);
if(pthread_join(pt,&res_t) != 0)
perror(“pthread_join”);
printf(“%dn”,a);
return 0;
}
a) 10
b) 20
c) segmentation fault
d) none of the mentioned
Ans- b) 20
Q – 76 What is the output of this program no 3?
#include
#include
int a;
void *fun_t(void *arg);
void *fun_t(void *arg)
{
printf(“%dn”,a);
pthread_exit(“Bye”);
}
int main()
{
pthread_t pt;
void *res_t;
a = 10;
if(pthread_create(&pt,NULL,fun_t,NULL) != 0)
perror(“pthread_create”);
if(pthread_join(pt,&res_t) != 0)
perror(“pthread_join”);
return 0;
}
a) 10
b) 0
c) -1
d) none of the mentioned
Ans- a) 10
Q – 77 What is the output of this program no 2?
#include
#include
void *fun_t(void *arg);
void *fun_t(void *arg)
{
printf(“%dn”,a);
pthread_exit(“Bye”);
}
int main()
{
int a;
pthread_t pt;
void *res_t;
a = 10;
if(pthread_create(&pt,NULL,fun_t,NULL) != 0)
perror(“pthread_create”);
if(pthread_join(pt,&res_t) != 0)
perror(“pthread_join”);
return 0;
}
a) 10
b) 0
c) -1
d) none of the mentioned
Ans- d) none of the mentioned
Q – 78 What is the output of this program no 1?
#include
#include
void *fun_t(void *arg);
void *fun_t(void *arg)
{
printf(“googlen”);
pthread_exit(“Bye”);
}
int main()
{
pthread_t pt;
void *res_t;
if(pthread_create(&pt,NULL,fun_t,NULL) != 0)
perror(“pthread_create”);
return 0;
}
a) this program will print the string “google”
b) this program will print nothing
c) segmentation fault
d) run time error
Ans- b) this program will print nothing
Q – 79 What is the output of this program?
#include
#include
void *fun_t(void *arg);
void *fun_t(void *arg)
{
int ret;
ret = pthread_exit(“Bye”);
printf(“%dn”,ret);
}
int main()
{
pthread_t pt;
void *res_t;
if(pthread_create(&pt,NULL,fun_t,NULL) != 0)
perror(“pthread_create”);
if(pthread_join(pt,&res_t) != 0)
perror(“pthread_join”);
return 0;
}
a) 0
b) 1
c) -1
d) none of the mentioned
Ans- d) none of the mentioned
Q – 80 Which one of the following string will print first by this program?
#include
#include
void *fun_t(void *arg);
void *fun_t(void *arg)
{
printf(“Googlen”);
pthread_exit(“Bye”);
}
int main()
{
pthread_t pt;
void *res_t;
if(pthread_create(&pt,NULL,fun_t,NULL) != 0)
perror(“pthread_create”);
printf(“Linuxn”);
if(pthread_join(pt,&res_t) != 0)
perror(“pthread_join”);
return 0;
}
a) Linux
b) Google
c) it can not be predicted
d) none of the mentioned
Ans- b) Google