2

This question already has an answer here:

I would like to be able to somehow modify a running command and/or get notified when a running command completes after it has been started.

Normally, when I know a command is going to take a long time, I will preemptively set something up for a notify:

./takes_long_time && touch done

or

./takes_long_time; touch done

My question is if ./takes_long_time was executed without the touch, is there a way I can go back and add it without restarting ./takes_long_time?

marked as duplicate by Anthon, Michael Homer, cuonglm, Networker, jimmij Feb 15 '15 at 10:36

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

0

Doing a bit more searching, I found the solution:

$ ./takes_long_time
<ctrl-z>
[1]+  Stopped ./takes_long_time

$ fg && touch done

There are some caveats depending on how you use this (fg; touch done may produce undesirable results, see linked post).

Also, you cannot do things like add a pipeline (fg | grep something), though this is an understandable limitation.

0

You will most likely have to put the ./takes_long_time in the background;

instead of

./takes_long_time && touch done

do

./takes_long_time &

This will place ./takes_long_time in the background to run. Afterwards you can execute ./takes_long_time. Hence, there will be two of these process running in the background.

An untraditional way of being notified of whether a command is finished can be like

if command_line; then 
    echo "It is done"
fi

example

if sleep 5; then 
echo "Finish sleeping for 5 seconds"
fi