# Signal Handler Inheritance ###### tags: `APUE` #### 整理:BY.Y, 2021/06/01 #### src: 超推薦👇👇👇👇 1. https://www.programmersought.com/article/34074981263/ ### Signal handlers are "inherited but not shared" 節錄自 https://stackoverflow.com/questions/23181282/sharing-vs-inheriting-signal-handlers-on-linux **Signal handlers are inherited.** This means the children inherit the same handlers as the parent has. **Signal handlers are not shared.** Calling the parent's handlers is not the same as calling a child's handlers. As the man page says, the signal is delivered to the parent after it is delivered to the children: hence different calls. ### Self-defined Sighandler Inheritance child會繼承parent的所有記憶體區段,包括.text section(signal handler) 為什麼exec會讓自定義的signal handler失效,最主要的原因是 exec 會覆蓋掉原本 child 的記憶體,使得自定義的函式無法被取得 > The child is a copy of the parent. For example, the child gets a copy of the parent’s data space, heap, and stack. Note that this is a copy for the child; the parent and the child do not share these portions of memory. The parent and the child share the text segment, however. > *ref. APUE Section8.3 fork Function* [name=SleepyCat1108] **Who knows what piece of code would be at that address when you replace the entire text segment?** *節錄自*[stack-overflow](https://stackoverflow.com/questions/2333637/is-it-possible-to-signal-handler-to-survive-after-exec)