# Segfaults, other signals, fork, etc

**URL:** <https://www.ruby-forum.com/t/segfaults-other-signals-fork-etc/92620>\
**Category:** Ruby\
**Created:** [April 21, 2007, 6:03pm UTC](https://www.ruby-forum.com/t/segfaults-other-signals-fork-etc/92620 "2007-04-21T18:03:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ehird](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/43a26b/32.png) [@ehird](https://www.ruby-forum.com/u/ehird)\
**Post date:** [April 21, 2007, 6:03pm UTC](https://www.ruby-forum.com/t/segfaults-other-signals-fork-etc/92620/1 "2007-04-21T18:03:49Z")

</div>

I have this code:

Process.waitpid(fork { exec “stuff” })

Outside of the fork, how can i detect various signals sent to stuff?  
SIGSEV, etc.

---

<div class="post-metadata">

**Author:** ![ehird](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/43a26b/32.png) [@ehird](https://www.ruby-forum.com/u/ehird)\
**Post date:** [April 21, 2007, 6:35pm UTC](https://www.ruby-forum.com/t/segfaults-other-signals-fork-etc/92620/2 "2007-04-21T18:35:34Z")

</div>

On 21.04.2007 18:03, Elliott H. wrote:

> I have this code:
> 
> Process.waitpid(fork { exec “stuff” })
> 
> Outside of the fork, how can i detect various signals sent to stuff?  
> SIGSEV, etc.

IIRC you can detect signals only from within the process that receives  
those signals. So “stuff” would have to do it. If you want to  
interfere with this you need to make sure that whoever sends those  
signals sends them to the parent or some kind of proxy which can do  
anything with them (including forwarding to the child).

I believe the only way to influence this from the outside is when  
signals are set to “ignore”. The child will inherit the ignoring even  
after exec.

Kind regards

robert

---

<div class="post-metadata">

**Author:** ![ehird](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/43a26b/32.png) [@ehird](https://www.ruby-forum.com/u/ehird)\
**Post date:** [April 21, 2007, 7:36pm UTC](https://www.ruby-forum.com/t/segfaults-other-signals-fork-etc/92620/3 "2007-04-21T19:36:23Z")

</div>

Robert K. wrote:

> IIRC you can detect signals only from within the process that receives  
> those signals. So “stuff” would have to do it. If you want to  
> interfere with this you need to make sure that whoever sends those  
> signals sends them to the parent or some kind of proxy which can do  
> anything with them (including forwarding to the child).  
> Would it be possible with Kernel#system()?

> Kind regards
> 
> robert

---

<div class="post-metadata">

**Author:** ![ehird](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/43a26b/32.png) [@ehird](https://www.ruby-forum.com/u/ehird)\
**Post date:** [April 22, 2007, 2:07am UTC](https://www.ruby-forum.com/t/segfaults-other-signals-fork-etc/92620/4 "2007-04-22T02:07:11Z")

</div>

Hi,

At Sun, 22 Apr 2007 01:03:51 +0900,  
Elliott H. wrote in [ruby-talk:248642]:

> I have this code:
> 
> Process.waitpid(fork { exec “stuff” })
> 
> Outside of the fork, how can i detect various signals sent to stuff?  
> SIGSEV, etc.

You can detect how the child process exited with $?, or waitpid2.

$ ruby -e ‘pid = fork {exec “sleep 10”}; sleep 0.1;  
Process.kill(“TERM”, pid); p Process.waitpid2(pid)’  
[23366, #\<Process::Status: pid=23366,signaled(SIGTERM=15)\>]
