Interview Questions Answers.ORG
Interviewer And Interviewee Guide
Interviews
Quizzes
Home
Quizzes
Interviews Linux OS Interviews:Awk ProgrammingBash Arithmetic ExpressionsDevice DriversGCC CompilerLinux AdministratorLinux CommandsLinux DebuggingLinux EnvironmentLinux GeneralLinux IPCLinux MakefileLinux OSLinux OS EditorsLinux OS ManagementLinux OS ShellLinux Proc FilesystemLinux Search PatternLinux Shared & Static LibrariesLinux Socket ProgrammingLinux Startup and ShutdownLinux SysfsLinux SystemsLinux ThreadsLinux UbuntuSignal HandlingSystem Calls
Copyright © 2018. All Rights Reserved
Linux Debugging Interview Question:
What is the output of this program no 11?
#include<stdio.h>
#include<stdlib.h>
#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
Submitted by: Murtazad) none of the mentioned
Explanation:
The program will not work properly because the file descriptor is not available in the for listen() and accept().
Output:
[root@localhost google]# gcc -o san san.c
[root@localhost google]# ./san
accept: Success
listen: Bad file descriptor
[root@localhost google]#
Submitted by: Murtaza
Explanation:
The program will not work properly because the file descriptor is not available in the for listen() and accept().
Output:
[root@localhost google]# gcc -o san san.c
[root@localhost google]# ./san
accept: Success
listen: Bad file descriptor
[root@localhost google]#
Submitted by: Murtaza
Copyright 2007-2024 by Interview Questions Answers .ORG All Rights Reserved.
https://InterviewQuestionsAnswers.ORG.
https://InterviewQuestionsAnswers.ORG.