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

  • Home
  • SEARCH
  • 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 501151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:09:37+00:00 2026-05-13T06:09:37+00:00

I’ve starting using socketpairs on linux and windows in order to capture the output

  • 0

I’ve starting using socketpairs on linux and windows in order to capture the output of subprocesses on both platforms. I do this by copying STD* onto one of the sockets in the socketpair (I’m using Win32::SocketPair in perl for socketpair’s on windows). The main reason I am doing this is so that read do NOT block on the output file handles.

The problem I have is that kill(0,…) doesnt work on windows, so I need another way to detect the process as down. I looked into SO_KEEPALIVE, but that doesn’t seem to work on socketpairs… I used setsockopt(…) then getsockopt(…) and the SO_KEEPALIVE option was off before and after the call to setsockopt().

Then I started looking into polling for events on the socket. The POLLHUP event looked promising, but I’m not sure it works when they’re used like this.

I’m looking to automate interactive programs (no, I can’t use Except as it doesn’t work on windows platforms… unless you found one that does?). I’ve been testing with “cat” on windows (I have cat.exe installed). It has looked good so far, but there are 2 issues:

  • can’t detect if process just dies (kill(0,…) doesnt work)
  • can’t detect EOF from subprocess (sysread seems to always return undef or bytes read, never 0, even after I shutdown($sock, 1))

I may be doing something extremely dumb, but any advice/help would be appreciated.

UPDATE: I started using waitpid($pid, WNOHANG) to detect the “still running” condition which helps as it seems the process always dies after everything has been read. waitpid returns 0 if the pid is still running. However, it’s not an EOF, its better than nothing, but I’m still looking for other input. This obviously isn’t ideal.

UPDATE2: This Q/A helped with the EOF part of my question, not perfect, but better:
How epoll detect clientside close in Python?

  • 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-13T06:09:37+00:00Added an answer on May 13, 2026 at 6:09 am

    In Linux, you can set a socket to be non-blocking (since at least 5.8):

     $socket->blocking(0);   # or (*SOCKET)->blocking(0);
    

    That doesn’t work on Windows (well, maybe it does in 5.10), but you can use the 4-arg select call to see if there is input on a socket before you attempt to read it (and in Windows, 4-arg select only works on sockethandles, not on filehandles or pipes).

    If you still need to tell whether a Windows process (with a known PID) is active, checkout the
    Win32::Process::Open method, which will try to open a handle to a windows process and return zero on failure.


    EDIT: I didn’t notice before that you said the sockets come from subprocesses. In that case, you can just call

    waitpid $pid, WNOHANG;   # and    use POSIX ':sys_wait_h'
    

    at any time. When waitpid doesn’t return -1, you know the process is dead.

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

Sidebar

Ask A Question

Stats

  • Questions 350k
  • Answers 350k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can create a toggle since the key bindings are… May 14, 2026 at 6:57 am
  • Editorial Team
    Editorial Team added an answer Perhaps a syntax error in dbo.sp_ReportCountLORUsers.sql ? May 14, 2026 at 6:57 am
  • Editorial Team
    Editorial Team added an answer Use commons-configuration, it is designed (to a certain extend) to… May 14, 2026 at 6:57 am

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a French site that I want to parse, but am running into
I have text I am displaying in SIlverlight that is coming from a CMS

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.