bash - Why does asynchronous child become a zombie altough parent waits for it? -


i use following code start long running task asynchronously detect if fails @ beginning:

sleep 0.3 & long_running & wait -n # [error handling]  # other stuff.  # wait completion of 'long_running'. wait -n # [error handling] 

if sigint (using ctrl+c) script during waiting long running child, long running task continues , gets zombie after completion. furthermore parent script consumes full cpu. have sigkill parent rid of processes.

i know sigint ignored child (which reason continues till completion), but why parent such confusing state?
works (like expected) if kill child when sigint has been received (the commented trap below), want understand why not work other way.

below complete script. please refer https://gist.github.com/doak/08b69c500c91a7fade9f2c61882c93b4 more complete example/try-out:

#!/usr/bin/env bash  count="count=100000"  # adapt 'dd' lasts 3s. comment out run forever. #fail=yes  # demonstrates failure of background task.  # work. #trap "jobs -p | xargs kill" sigint  echo executing long running asynchronous task ... sleep 0.3 & dd if=/dev/zero$fail of=/dev/null bs=1m $count & wait -n errcode=$? if test $errcode -ne -0;     echo "failed"     exit $errcode fi  echo waiting completion ... wait -n errcode=$? echo finished exit $errcode 

it question related c question, although discusses system call wait(): possible parent process hang on "wait" step if child process becomes zombie or crashes?


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -