Skip to main content
added 281 characters in body
Source Link
user313992
user313992

You should ignore the ^C / SIGINT in the post-process function:

preprocess(){
   while echo baa; do sleep 1;yes donebaa
}
postprocess(){
   sed 's/a/z/g'
}
preprocess | { trap '' INT; postprocess; sleep 1; echo DONE; }

When you run that pipeline and press ^C, preprocess will be killed, but postprocess will continue running until all the output produced by preprocess has been consumed.

Notice that the trap '' INT (with an empty string as the handler) will also ignore SIGINT in the subprocesses; do not replace it with eg. trap 'echo INT trapped' INT because that will cause any sed, etc. to be killed too by '^C', despite the signal being handled in the parent process.

You should ignore the ^C / SIGINT in the post-process function:

preprocess(){
   while echo baa; do sleep 1; done
}
postprocess(){
   sed 's/a/z/g'
}
preprocess | { trap '' INT; postprocess; echo DONE; }

When you run that pipeline and press ^C, preprocess will be killed, but postprocess will continue running until all the output produced by preprocess has been consumed.

You should ignore the ^C / SIGINT in the post-process function:

preprocess(){
   yes baa
}
postprocess(){
   sed 's/a/z/g'
}
preprocess | { trap '' INT; postprocess; sleep 1; echo DONE; }

When you run that pipeline and press ^C, preprocess will be killed, but postprocess will continue running until all the output produced by preprocess has been consumed.

Notice that the trap '' INT (with an empty string as the handler) will also ignore SIGINT in the subprocesses; do not replace it with eg. trap 'echo INT trapped' INT because that will cause any sed, etc. to be killed too by '^C', despite the signal being handled in the parent process.

Source Link
user313992
user313992

You should ignore the ^C / SIGINT in the post-process function:

preprocess(){
   while echo baa; do sleep 1; done
}
postprocess(){
   sed 's/a/z/g'
}
preprocess | { trap '' INT; postprocess; echo DONE; }

When you run that pipeline and press ^C, preprocess will be killed, but postprocess will continue running until all the output produced by preprocess has been consumed.