A client process P needs to make a TCP connection to a server process S.…

2008

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 socket(), a bind() and a listen() system call in that order, following which it is preempted. Subsequently, the client process P executes a socket() system call followed by connect() system call to connect to the server process S. The server process has not executed any accept() system call. Which one of the following events could take place?

  1. A.

    connect () system call returns successfully

  2. B.

    connect () system call blocks

  3. C.

    connect () system call returns an error

  4. D.

    connect () system call results in a core dump

Attempted by 13 students.

Show answer & explanation

Correct answer: C

The server process S has executed socket(), bind(), and listen() but not accept(). When the client calls connect(), it attempts to establish a connection. Since no process has called accept() on the server side, the connection request remains in the queue but is not accepted. According to TCP semantics, if no process accepts the connection, connect() will fail with an error (e.g., ECONNREFUSED). Thus, the correct outcome is that connect() returns an error.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Gate Guidance By Sanchit Sir