2

I am running multiple semicolon-separated bash commands:

% long-running-command-I-want ; another-command-I-dont

The long-running-command-I-want is still running; naturally there is no pid of the another-command-I-dont yet. I'd like to preemptively kill/cancel/prevent from execution the another-command-I-dont without killing the long-running-command-I-want which I have been waiting for for a while. Can I do that? If so, how?

3

If you run another shell you can find out the PID of the bash which is running the program that you want to continue. If this is bashPID, then send an interrupt signal with:

kill -2 bashPID

This will stop the execution of the rest of the command line.

Optionally, in the original shell you can type Ctrl-z to suspend the running program temporarily in background. This would carry on with the rest of the command line, which will be flushed by the interrupt signal. You can then resume the running program with fg or bg, depending on whether you want it to continue in foreground or background.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.