Live data from Hacker News

Ctrl-C

kevinlawler.com

1–10 of 94 posts

Re: Ctrl-C

#2
A lot of multi threaded server software handles ctr+c just fine. A lot of Java based server software have a shutdown hook, which is something that you can easily add to any jvm based program because it is part of the standard library. If you use Spring Boot, for example, it has one and it will start shutting down your Spring Context and call any destroy functions on DestroyingBean implementations, which is how you can add your own shut down logic in Spring.

Good explanation here of shutdown hooks: https://www.baeldung.com/jvm-shutdown-hooks

Re: Ctrl-C

#3
After decades of experience I learned to use ctrl-\ (break) or ctrl-z and then kill -9 %1. Hope this helps someone.

Re: Ctrl-C

#4
post #3

After decades of experience I learned to use ctrl-\ (break) or ctrl-z and then kill -9 %1. Hope this helps someone.

Which is exactly what the author is saying shouldn't be needed.

Re: Ctrl-C

#5
Laugh all you want, but this is is precisely why I like "old-fashioned" asynchronous exceptions (the ones which unwind the stack), and ensure most programs are ready to handle a clean stack unwind at practically any point inside the program (e.g. asynchronous-unwind-tables).

Re: Ctrl-C

#6
post #4
post #3

After decades of experience I learned to use ctrl-\ (break) or ctrl-z and then kill -9 %1. Hope this helps someone.

Which is exactly what the author is saying shouldn't be needed.

Author is talking about looking up PIDs, kill -9 %1 saves you from that.

Re: Ctrl-C

#7

Laugh all you want, but this is is precisely why I like "old-fashioned" asynchronous exceptions (the ones which unwind the stack), and ensure most programs are ready to handle a clean stack unwind at practically any point inside the program (e.g. asynchronous-unwind-tables).

The way exceptions are handled as a result of siglongjmp'ing out of a signal handler is currently platform-inconsistent and one of the many dark areas I alluded to. It isn't even consistent on Linux between compilers.

Re: Ctrl-C

#8
post #6
post #4

Earlier quoted context omitted.

Which is exactly what the author is saying shouldn't be needed.

Author is talking about looking up PIDs, kill -9 %1 saves you from that.

It is true this improves the bad path. It ignores desired happy path cases: downstream processes, custom debugging, graceful shutdown, preserved workspaces, and so on.

Re: Ctrl-C

#9
> We don't want our ctrl-c to leak memory. […] If you allocate a piece of memory, you need to store a pointer to that memory from the object graph, and both of those operations need to occur inside of a critical section. Otherwise, if you get interrupted right after the allocation, there won't be any way to reach your memory and it will leak.

Maybe I'm missing something here but… so what? If at the end of your Ctrl+C signal handler you exit() as expected, then the OS will clean up your process's memory anyway.

Re: Ctrl-C

#10
post #3

After decades of experience I learned to use ctrl-\ (break) or ctrl-z and then kill -9 %1. Hope this helps someone.

Excellent advice, thanks for sharing. Would in turn recommend using CopyQ to store this tips (and other like it) as a pinned items in folder with explanations for use two years later, that's how I personally stay on top of terminal kung-fu without overloading the consciousness-in-meat*

* https://www.mit.edu/people/dpolicar/writing/prose/text/think...

Post reply on HN