41⟩ The execution of the program in GDB can be affected by a) arguments b) working directory c) environment d) all of the mentioned
d) all of the mentioned
“Linux Debugging frequently Asked Questions by expert members with experience in Debugging. These questions and answers will help you strengthen your technical skills, prepare for the new job test and quickly revise the concepts”
d) all of the mentioned
c) error
Explanation:
The header file netinet/in.h is required to use the structure sockaddr_in.
Output:
[root@localhost google]# gcc -o san san.c
san.c: In function 'main':
san.c:7:21: error: storage size of 'addr' isn't known
[root@localhost google]#
b) error at the time of compilation
Explanation:
The third argument of the accept is the type of pointer.
Output:
[root@localhost google]# 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'
[root@localhost google]#
a) the system having IP address 193.39.0.4
Explanation:
The IP address is mentioned in the proper element of the structure sockaddr_in
a) IPv4
b) -1
Explanation:
The shutdown() is used to close a socket and the first argument in shutdown() is socket.
Output:
[root@localhost google]# gcc -o san san.c
[root@localhost google]# ./san
-1
[root@localhost google]#
a) it can not accept the request of any client
d) none of the mentioned
Explanation:
The listen() must always be used before accept().
Output:
[root@localhost google]# gcc -o san san.c
[root@localhost google]# ./san
accept: Invalid argument
[root@localhost google]#
d) 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]#
a) socket()
a) the server will write back to the client whatever the client will write to the server
Explanation:
The loopback address is used as IP address in both the programs.
d) none of the mentioned
Explanation:
To use socket(), the header files sys/types.h and sys/socket.h are required.
Output:
[root@localhost google]# gcc -o san san.c
san.c: In function 'main':
san.c:6:21: error: 'AF_UNIX' undeclared (first use in this function)
san.c:6:21: note: each undeclared identifier is reported only once for each function it appears in
san.c:6:29: error: 'SOCK_STREAM' undeclared (first use in this function)
[root@localhost google]#
a) TCP/IP
c) in the present working directory
Output:
[root@localhost google]# ls
san.c
[root@localhost google]# gcc -o san san.c
[root@localhost google]# ./san
[root@localhost google]# ls
san san.c san_sock
[root@localhost google]#
d) 3
Explanation:
The second argument of listen() specifies the length for the queue for pending connections.
b) the process will remain block
Explanation:
There is no peding request in the queue for listening socket "san_sock".
Output:
[root@localhost google]# gcc -o san san.c
[root@localhost google]# ./san
^Z
[4]+ Stopped ./san
[root@localhost google]#
d) 3
Explanation:
The socket() returns the lowest available file descriptor and in this program i.e. 3.
Output:
[root@localhost google]# gcc -o san san.c
[root@localhost google]# ./san
3
[root@localhost google]#
a) this program will print the string "google"
Explanation:
The first argument of the bind() is not a valid file descriptor in this program.
Output:
[root@localhost google]# gcc -o san san.c
[root@localhost google]# ./san
Sanfoudnry
[root@localhost google]#
a) the listen() is missing
c) error
Explanation:
The syntax of the connect() is wrong. connect() should be used in client program only.
Ouptut:
[root@localhost google]# gcc -o san san.c
san.c: In function 'main':
san.c:20:46: warning: passing argument 3 of 'connect' makes integer from pointer without a cast [enabled by default]
/usr/include/sys/socket.h:129:12: note: expected 'socklen_t' but argument is of type 'int *'
[root@localhost google]#