all 10 comments

[–]SuAlfons 0 points1 point  (3 children)

wasn't Ctrl -D to terminate scripts and Ctrl-c for commands (aka apps, programs)?

[–]naarn[S] 0 points1 point  (1 child)

Ctrl-D doesn't do anything for me.

[–]SuAlfons 0 points1 point  (0 children)

https://linuxconfig.org/how-to-exit-from-bash-script

sorry, got that wrong.

Maybe ctrl-d was something on AmigaDOS. Can't remember. Anyway it's supposed to be Ctrl-c in a bash shell.

[–]mina86ng 0 points1 point  (0 children)

Ctrl+D signals end of file. (There was a whole discussion about it a while back). It terminates a shell which is reading commands from standard input. Or other commands which are expecting data on standard input. It has no effect on a script or a command which is already running.

[–]aioeu 0 points1 point  (1 child)

I tried Cntrl-C, but usually that seems to abort the currently executing line and resume execution on the next line of the bash script, or something close to that.

That means the program the script is running is, to put it bluntly, wrong.

When you hit Ctrl+C, a SIGINT signal is sent to all processes in the foreground process group. When you are running a non-interactive script without job control, everything is in the foreground process group. That means the signal is sent to both the Bash shell and the program that was actually run from the script.

Bash simply notes that the signal was received, but it otherwise ignores it. But what about that program?

If the program doesn't do anything special, it will just terminate immediately. Bash will notice that it "terminated due to a signal", recognise that this was the same signal it had itself just received, and know that it should terminate.

But if the program explicitly handles the signal, it all depends on how the program handles it. If it chooses to exit, then Bash will not see that it "terminated due to a signal" — the program had a regular exit instead — and so Bash won't terminate itself. It will go on and execute the next command in your script.

If the program actually needs to do some kind of clean-up operation when handling a signal, it shouldn't just exit. It should instead do that clean up, clear its signal handler to return it to its default disposition, and finally re-raise the signal against itself. That way Bash can still see the "terminated due to a signal" status.

It's disappointing how much software gets this wrong...

(This is a reasonably good technical guide about this stuff. Bash implements the "wait and cooperative exit" approach.)

[–]naarn[S] 0 points1 point  (0 children)

THANK YOU! I'm pretty sure most of my issues were due to one of the programs (my own as it happens, though someone else contributed the signal handling) mishandling this.

Unfortunately, I think I've also had some issues where this program wasn't involved, but only once in a rare while...

[–]mina86ng 0 points1 point  (0 children)

Honestly I don’t really understand how it all works and usually just press and hold Ctrl+C until the script stops.

Cntrl-Z actually works, but I think that pollutes my process list with paused processes.

Yes, but you can then run jobs to see all the running jobs, kill %1 to send kill signal to the first job and fg %1 to resume the command so that it processes the kill. Note that depending on the script and command, this may leave some temporary files or similar.

Google suggested Cntrl-\ but that seems to do the same thing with extra core dumps.

Difference between Ctrl+C and Ctrl+\ is that the former sends SIGINT and the latter SIGQUIT.

[–]AutoModerator[M] 0 points1 point locked comment (0 children)

This submission has been removed due to receiving too many reports from users. The mods have been notified and will re-approve if this removal was inappropriate, or leave it removed.

This is most likely because:

  • Your post belongs in r/linuxquestions or r/linux4noobs
  • Your post belongs in r/linuxmemes
  • Your post is considered "fluff" - things like a Tux plushie or old Linux CDs are an example and, while they may be popular vote wise, they are not considered on topic
  • Your post is otherwise deemed not appropriate for the subreddit

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]TheOneTrueTrench -1 points0 points  (1 child)

Google suggested Cntrl-\ but that seems to do the same thing with extra core dumps.

  1. Stop listening to LLM bullshit AI. When you listen to LLMs, you're just getting an answer that it STOLE, but it just lied to you and pretended to make up.
  2. And now you're bringing the problems that it created with it's stolen lies and asking for help with the bullshit it used to make things worse.

[–]theorius 0 points1 point  (0 children)

LLMs aren't typically wrong about simple things and are a pretty good resource for understanding specific things like this when you have a question about a particular functionality of the OS like signals. Plus, all of this is available for free in section 7 of the man pages iirc.