Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5837871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:24:27+00:00 2026-05-22T11:24:27+00:00

I have a program that serves as a TCP server that listens to port

  • 0

I have a program that serves as a TCP server that listens to port 5000, for example.

Now I want to run another command-line process to run in parallel with this server. I know the right way to do it is to fork the server, than call “exec” ….

My question is, is the child process also “owns” this port 5000? If I want to release this port 5000, do I need to kill both the parent process and the child process?

I am just very curious how this socket connection is being handled in the forking.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T11:24:28+00:00Added an answer on May 22, 2026 at 11:24 am
    1. First, accept() the incoming connection. The accepting process now has a handle to the listening socket, and the newly accepted socket.
    2. Fork and:
      • In the child:
        1. Close the listening socket.
        2. Do stuff with the accepted socket.
      • In the parent:
        1. Close the accepted socket.
        2. Resume the accept loop.

    The various socket resources will be reclaimed when all references to the handle are closed. If a process terminates, all its handles are closed implicitly. Therefore if a child closes the handle it inherits to the listening socket, the only handle remaining to that socket exists in the parent. Then the listening socket will be reclaimed when the parent terminates, or closes this handle explicitly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small server program that accepts connections on a TCP or local
I have a .Net program that I want to install on a terminal server.
I have a server program that connects to another program via a given socket,
I have a server program that reads data from a remote stream via TCP,
I have a 'server' program that updates many linked lists in shared memory in
I have a program that report exceptions to my server. I'd like to also
I have a program that runs osql.exe from microsoft sql server tools directory and
I have a program that downloads PCM data from a Web Server, which it
I have a program that is supposed to interact with a web server and
I have a program that will let me manage users on our terminal server

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.