If two jobs are entered into bash command line separated by semicolon:
$ job 1; job 2;
How do I cancel the second one? If I press CTRL+c, the first one will be canceled and 'job 2' would start, I just want to stop second job not to be executed. I tried atq, ps but no luck, with ps -ef I can see only 'job 1' but 'job 2' is not listed, so I can not get PID to use kill. I know I can use && instead of ; but it is too late now, I ran this command by accident on my server instead of my home PC and now I am trying to figure out how to prevent a disaster.
This problem is specific to rsync command followed by another command:
$ rsync ..... ; sudo shutdown -h now
Killing process by ID or killing it's parent will not work.
After several hours of testing, I isolated it to rsync, other commands I am able to terminate with CTRL+c in various orders, but not if they are after some commands like rsync or ping, I tried different Ubuntu versions, kernels, server without sudo user and I could reproduce it everywhere, best way to avoid this problem is to use && after rsync to execute following command only on success exitcode 0:
$ rsync .... && job 2
Kill the parent process of job1 with
SIGKILL
.Show the processes in a process tree, eg. with
htop
orps axf
and kill the parent process of job1 and not job1 itself.Install
htop
withDownvoters, understand the answer before downvoting
I think you miss something, When you run two commands seperated by
;
you can kill the both commands by the CTRL+c.just to be sure try this command:
Then kill the above commands with CTRL+c, this would kill both processes, you'll not list your home content. I.e, the next command will not run.
UPDATE: This also will be valid for your
rsync
command. Here my example:So as you see above When you run CTRL+c, this kill the first command and while starting shudown it will ask you for your
sudo
password, so you can now kill the second process using CTRL+c again.Update 2 As a hack for problem you can do:
sudo
then make again yoursudo
ask for password by editing your sudoer filesudo visudo
/sbin/shutdown
command to remove+x
or just rename it to different name.