I am running multiple commands on the command line separated using semi-colons:
cmd1; cmd2; cmd3
If I press Ctrl+C on the above, it would kill all commands instead of just the one which is executing currently.
kartik@kartikpc:~/junk/exp$ ls
test1 test2
kartik@kartikpc:~/junk/exp$ cat; ls
cat is running
cat is running
^C
kartik@kartikpc:~/junk/exp
But Ctrl+Z would only suspend the current process and continue with the next one.
kartik@kartikpc:~/junk/exp$ ls
test1 test2
kartik@kartikpc:~/junk/exp$ cat; ls
cat is running
cat is running
^Z
[1]+ Stopped cat
test1 test2
kartik@kartikpc:~/junk/exp$
Why is there a disperancy in behaviour, and is there any way to make Ctrl+C behave like Ctrl+Z?
I'm actually running a server through tmux session as follows node app.js; $bash
, and when I do a Ctrl+C to kill the server, it kills bash as well. I want to return to shell. Is there any alternative to achieve the behavior I want?
[UPDATE]
tcsh
behaves the same with Ctrl+C and Ctrl+Z. It would always act on all commands just as bash is doing with onlt Ctrl+C. But bringing back the job with fg
would only bring back cat
and not ls
.
[kartika@vm-kartika-vnc ~/junk]$ ls
file1 file2
[kartika@vm-kartika-vnc ~/junk]$ echo $SHELL
/bin/tcsh
[kartika@vm-kartika-vnc ~/junk]$ cat; ls
cat is running
cat is running
^C
[kartika@vm-kartika-vnc ~/junk]$ cat ; ls
cat is running
cat is running
^Z
Suspended
[kartika@vm-kartika-vnc ~/junk]$ jobs
[1] + Suspended cat
[kartika@vm-kartika-vnc ~/junk]$ fg
cat // Pressing ctrl-d here to exit cat
[kartika@vm-kartika-vnc ~/junk]$
System Information:
kartik@kartikpc:~/junk/exp$ uname -a
Linux kartikpc 3.13.0-70-generic #113-Ubuntu SMP Mon Nov 16 18:34:13 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
kartik@kartikpc:~/junk/exp$ echo $SHELL
/bin/bash
grep SigIgn /proc/$$/status
have the 4 bit on in the lowest position? That's often the case. Then you can type Control-backslash to send a SIGQUIT to kill the foreground job without making the shell discard the rest of the command line. But it may produce a core dump of the foreground job, depending on your configuration.