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 430711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:54:09+00:00 2026-05-12T19:54:09+00:00

I have a small application that redirects the stdout/in of an another app (usually

  • 0

I have a small application that redirects the stdout/in of an another app (usually command prompt or bash for windows). The problem is that if the connection is interrupted the my process has no idea and it never closes because of this line:

WaitForSingleObject(childProcess.hThread, INFINITE)

I was thinking of having a loop with something like this:

while(true)
{
     if(ProcessIsDead(childProcess.hThread))
      // close socket and exit
    if(SocketIsDisocnnected(hSocket))
    // close process and exit

}

What functions would I use to accomplish this? For ProcessIsDead I know there is a winapi for getting the exit code but I don’t know how to check if the socket is disconnected without calling recv (which i cant do)

  • 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-12T19:54:09+00:00Added an answer on May 12, 2026 at 7:54 pm

    Note: I’m assuming the connected socket is communicating over a network link, because I’m not sure how it would become disconnected if it were a local pipe, except by one process or the other dying.

    Use the select() function in the socket API to query the read status of the socket. select() will tell you the socket is “readable” if any of the following is true:

    • If listen has been called and a connection is pending, accept will succeed.
    • Data is available for reading (includes OOB data if SO_OOBINLINE is enabled).
    • Connection has been closed/reset/terminated.

    So, if select() says that the socket is readable, it is safe to call recv(), which will give you WSACONNRESET or return 0 bytes if the connection was reset or closed respectively. select() takes a ‘timeout’ parameter, which you can set to an appropriate time interval or zero if you want to poll the socket state.

    Information on the select() function is at http://msdn.microsoft.com/en-us/library/ms740141(VS.85).aspx

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

Sidebar

Related Questions

I have small application that is uploading pictures to another website via webservice. My
I have a small application that I've written and it talks to another application
I have a small application that uses WCF to communicate with a webserver. This
I have a small application that I am building a Chat application into, so
I have a small application that uses a SharePoint list as the data source.
This is getting me quite confused: I have a small application that uses a
I have a small homework application that writes random numbers from 5 to 77
I have a small shell application that embeds Tcl to execute some set of
I have a small application which embeds webbrowser controls. In that application I have
I have a small GTK python application that imports a package (Twisted) that may

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.