How can I timeout a forked process that might hang?

后端 未结 4 556
走了就别回头了
走了就别回头了 2021-02-09 08:36

I am writing a Perl script that will write some inputs and send those inputs to an external program. There is a small but non-zero chance that this program will hang, and I want

4条回答
  •  梦如初夏
    2021-02-09 09:26

    Hmmm your code works for me, after some minor modifications - which I assume are changes made by yourself to make the code into a generic example.

    So that leaves me with two ideas:

    1. You removed the problem when you created the sample code - try creating a small sample that actually runs (I had to change 'program_of_interest' and $num_secs_to_timeout to real values to test it). Make sure the sample has the same problem.
    2. It's something to do with the program_of_interest you're running - as far as I know, you can't mask a kill 9, but maybe there's something going on. Have you tried testing your code with a really simple script. I created one for my testing that goes while (1) { print "hi\n"; sleep 1; }
    3. Something else.

    Good luck...

提交回复
热议问题