6

I have a bash script I use to run XCode on OS X, which takes several minutes. I can't find the key command to stop it if I realize an error... on DOS I'm used to Ctrl+C/Ctrl+Z but neither seem to work. What am I looking for (on the standard OS X terminal)?

3
  • 1
    ctrl C should send sig-term (this signal can be trapped), and ctrl z send sig stop (both (all) key sequences can be blocked.) You need to set keyboard focus to terminal first. (this comment is for any generic Unix system) – ctrl-alt-delor Sep 30 '12 at 19:40
  • 1
    @richard Ctrl-C sends SIGINT, not SIGTERM. SIGINT should terminate the process – Rich Homolka Oct 1 '12 at 18:27
  • @ctrl-alt-delor Ctrl+Z sends SIGTSTP (which can be caught), not SIGSTOP (which cannot be caught). – Josh Correia Jan 30 '20 at 20:16
6

There are a few keypresses that should help you here.

Ctrl+C should send the foreground process SIGINT, and that should terminate the process unless you trap the signal with something like trap INT ... in your shell code.

Ctrl+Z should send SIGSTOP, which would pause your process, again unless you trap your signals.

The mapping of key sequences jumps through some hoops, including terminal settings. What does stty -a say on your computer? Look in the output for intr, that's the keypress that should trigger SIGINT. If nothing is set, you need to set it, something like stty intr ^C

As others have said, you can kill the process from another window as well.

1

If Ctrl + C isn't working for you, you can open a new Terminal tab and type

killall [process name]

where [process name] is the name of your bash script (you can find this in OS X's Activity Monitor).

1

You can try these solutions :

  • try this keyboard combo : Ctrl+AltGr+8
  • open a new terminal and run pkill -f script_name
1
  • These are not applicable to OS X. – Gordon Davisson Sep 30 '12 at 20:49
0

To add on to what other users have said, you can also use Ctrl+\ which sends SIGQUIT and is the same as SIGINT except it also produces a core dump. I've found that programs which ignore SIGINT often do not ignore SIGQUIT.

Based on the man-page for kill, you are also able to send a SIGTERM or SIGKILL to any process. You would accomplish this by finding your process in the process table (type ps) and then type kill -15 [pid] to send a SIGTERM or kill -9 [pid] to send a SIGKILL (SIGKILL can't be ignored and will kill the process no matter what).

Source 1 and Source 2

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.