The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
+25 votes

A client process P needs to make a TCP connection to a server process S. Consider the following situation: the server process S executes a $\text{socket()}$, a $\text{bind()}$ and a $\text{listen()}$ system call in that order, following which it is preempted. Subsequently, the client process P executes a $\text{socket()}$ system call followed by $\text{connect()}$ system call to connect to the server process S. The server process has not executed any $\text{accept()}$ system call. Which one of the following events could take place?

  1. $\text{connect()}$ system call returns successfully

  2. $\text{connect()}$ system call blocks

  3. $\text{connect()}$ system call returns an error

  4. $\text{connect()}$ system call results in a core dump

asked in Computer Networks by Veteran (69k points) | 2.6k views
CAN any1 explain in what cases the call is blocked and call results in core dump.....what is this core dump??
what is "CORE DUMP"

A core dump is the printing or the copying to a more permanent medium (such as a hard disk) the contents of random access memory ( RAM ) at one moment in time. One can think of it as a full-length "snapshot" of RAM. A core dump is taken mainly for the purpose of debugging a program

Diagram --> 

For explanation watch from time 6:00 --> 

so here both the client and server are deployed in the same machine ?? @reena_kandari

so here in this case if the premption takes place after calling accept() then the option would be B

2 Answers

+55 votes
Best answer

First thing to note: All the sockets are by default in BLOCKING mode. What do we mean by blocking ??

Blocking mode means that when we make a system call, it blocks the caller for the time "when call() is made till the job is done OR an error returns ". We can set each socket to Non-blocking explicitly. Setting to Non-Blocking means we are telling the kernel that "If the system call cant be completed without putting process to sleep then DON'T put the process to sleep . Instead return with an ERROR immediately and continue the process" which can be checked for the completion by the caller in between the execution of other tasks.

Now coming to this question:

Suppose connect() is in default blocking mode then calling connect() sends SYN packet to the server. Since server has not executed any accept() call it can not acknowledge the SYN packet. Connect() in blocking mode keep sending SYN packets at fixed intervals(first after 6 sec, second after 24 sec typically until 75 sec latest). This is done until an error ETIMEDOUT is returned by the TCP.(in this case,else there are several other type of errors returned in case No port exists for that connection or server id not listening etc.)

here option (B) saying that connect() blocks is not entirely wrong but since we know that accept() call is not made by server, connect() WILL NOT WAIT FOREVER and SO IT CAN NOT BLOCK. It will ultimately return with an ERROR message.

So option (c) is CORRECT.


Core dump thing I don't know about !!


But once connect() returns error that socket can not be reused and must be CLOSED.


And a non-blocking connect() is never blocked and immediately returns with an error if connection is not successful although IT CONTINUES WITH TRYING TO CONNECT .Error here just means that it returns a message saying "I could not connect immediately BUT i am trying AND you can check it in between.

Hope it clears a bit.

answered by Boss (7.7k points)
selected by
Any references Sandeep ?
+12 votes

Simple it is. given that the server process is preempted before client requests anything. It means that calling the connect() system call will try to establish a TCP connection (will send SYN) but since the server at the expected port is not present at the destination, a host unreachable - port unreachable error will be returned by the ICMP.


answered by Active (2.3k points)

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

34,170 questions
40,846 answers
39,703 users