Simple Linux Signal Handling

后端 未结 5 561
天涯浪人
天涯浪人 2020-11-30 00:49

I have a program that creates many threads and runs until either power is shutdown to the embedded computer, or the user uses kill or ctrlc

5条回答
  •  隐瞒了意图╮
    2020-11-30 01:27

    1. Is any signal handling necessary?

    • In the particular case of the link you posted, yes. The runs of softwares that concerns network need particular operations, as warning client of the close of a socket by example, in order to not disturb its run.
    • In your particular case, you don't need to handle any signal for the process to be clear gracefully : your OS will do it for you.

    2. Are there any other signals that I need to be concerned with regarding clean termination?

    • First, take a look at his page : The GNU Library Signals The termination signals is what you look after. But take a look at SIGUSR1 and SIGUSR2, even if you 'll never find them in any software, except for debugging purposes.

    • All of this termination signals need to be handled if you don't want your soft to terminate all of a sudden.

    3. Does the terminate variable in my example have to be volatile?

    • Absolutely not.

    4. I've read that signal() is now deprecated, and to use sigaction()

    • Sigaction() is POSIX while signal is a C standard.

    • Signal() works fine for me, but if you want any example : IBM Example

提交回复
热议问题