-1

I have a process, and when I issue ctrl+c in the terminal, it closes the terminal window completely, anybody know why that might be happening?

This is how the process is now started:

exec "$(dirname "$0")/suman-shell"    # a

it used to be started like so, and there was no problem:

"./$(dirname "$0")/suman-shell"       # b

it does look like using exec is what is causing the terminal window to close, so why does a close the terminal window, but not b, after receiving a signal?

3
  • You don't give much detail, but if the process is started with exec and is killed with Ctrl-C, then there is no shell to return to. In this case the terminal emulator quits, just like it quits when you exit a shell running in it. Commented Nov 5, 2017 at 10:09
  • 1
    You can attach strace to the terminal emulator and to the application. Then you should see what happens. I assume that either the process has been started with exec from the running shell (so that the terminal window would close after the process exits normally, too) or that the signal handler (whyever) kills the terminal emulator. Commented Nov 5, 2017 at 11:26
  • thanks for comments - indeed it does seem like an issue with using exec! I would never have figured that out if it weren't for these comments - any idea why a and b behave differently? (see updated question). Commented Nov 5, 2017 at 17:37

1 Answer 1

2

Usually all commands (which are not shell builtins) are executed in a subshell i.e. the main process forks and the new process executes (becomes) the command while the main process (usually) waits for the child process to finish.

That is the reason why (apart from sending a signal) the child process cannot affect the main process.

If a command is started with the shell builtin exec then the main process does not fork but turns into the command (via the syscall execve()). Thus after the exit of the command there is no more main process to return to.

From the perspective of the terminal emulator the shell has exited (as soon as the exec command has exited) and thus the window closes.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.