1

I started using Sublime Text 3 to compile my FreeFem scripts (interpretator PDEs package solver) under Ubuntu 14.04. To invoke the interpretator I customized the build system as follows

"shell_cmd": " gnome-terminal -x sh -c \"FreeFem++ $file ; exec sh\""

Every time I run compilation I want to create a separate terminal process that launches FreeFem++. But when I press Ctrl+C it kills the terminal. Instead of this I want to terminate process but leave the terminal window open.

0

Ctrl+C kills the shell as well as the FreeFem subprocess, because the SIGINT signal is sent to the whole foreground process group. Since the shell is not interactive, the subprocess runs in the same process group. See Why is SIGINT not propagated to child process when sent to its parent process? and What is the purpose of abstractions, session, session leader and process groups? for some background on process groups.

You can cause the shell not to die when it receives SIGINT by setting a trap for it. (Don't ignore the signal: that would also cause it to be ignored by the subprocess.)

"shell_cmd": " gnome-terminal -x sh -c \"trap echo INT; FreeFem++ $file ; exec bash\""
  • What do you mean by Don't ignore the signal? – afuna Jan 1 at 10:56
  • @afuna A process can decide how it handles each signal (this is called the signal's disposition): default action (for most signals, that's termination), run code (a handler), or ignore it (i.e. nothing happens when the process receives the signal). – Gilles Jan 1 at 11:39
  • I meant, do you mean trap echo INT as opposed to trap INT or did you have something else in mind? – afuna Jan 1 at 11:52
  • 1
    When I write “ignore the signal”, I mean the standard meaning of “ignore the signal”. It's standard terminology. In a shell script, trap '' INT sets SIGINT's disposition to “ignore”. – Gilles Jan 1 at 11:56

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.