Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Hello Monks,

I am looking for a "clean" way to terminate processes I've created on both Linux and Windows.

The processes exec an external program which in some situations intentionally runs "forever", or until stopped by someone else.

On Linux, this is straightforward: $child_pid = fork, then in the child process exec. Later, kill 1, $child_pid from the parent process.

On Windows (Windows 11 in my case), fork and exec are emulated but work quite fine... only that I don't know how to kill the subprocess. The PID returned from fork is apparently useless. When I kill 1 $child_pid, the main process complains Terminating on signal SIGHUP(1) and terminates immediately, leaving the external process running like a zombie. I can get rid of the zombie by entering Ctrl-C on the command line.

On Windows - and only on Windows - I can replace fork, exec and kill by the corresponding functions from Win32::Process. If I just use Win32::Process, then this would be a dependency also on Linux, which is unwanted, so I'd go for a solution with if, and write two separate helper modules.

Has this exercise already been done? I didn't find anything under Process...


In reply to How to portably stop processes? by haj

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2023-12-08 04:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?











    Results (35 votes). Check out past polls.

    Notices?