# Win32 Process Signals

**URL:** <https://www.ruby-forum.com/t/win32-process-signals/134809>\
**Category:** Ruby\
**Created:** [April 15, 2008, 11:20am UTC](https://www.ruby-forum.com/t/win32-process-signals/134809 "2008-04-15T11:20:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sealedsun](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e68b1a/32.png) [@sealedsun](https://www.ruby-forum.com/u/sealedsun)\
**Post date:** [April 15, 2008, 11:20am UTC](https://www.ruby-forum.com/t/win32-process-signals/134809/1 "2008-04-15T11:20:32Z")

</div>

Hey!

I user win32/Process to spawn a child Process in my Application

myProc = Process.create(:app\_name =\> “ruby test.rb”)

and kill it with

Process.kill(1, myProc.process\_id)

How can i trap the signal in the Child Process to do cleanup stuff?

thx

---

<div class="post-metadata">

**Author:** ![sealedsun](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e68b1a/32.png) [@sealedsun](https://www.ruby-forum.com/u/sealedsun)\
**Post date:** [April 15, 2008, 2:55pm UTC](https://www.ruby-forum.com/t/win32-process-signals/134809/2 "2008-04-15T14:55:47Z")

</div>

## $ ri Signal.trap ----------------------------------------------------------- Signal::trap Signal.trap( signal, proc ) =\> obj Signal.trap( signal ) {| | block } =\> obj

```
 Specifies the handling of signals. The first parameter is a signal
 name (a string such as ``SIGALRM'', ``SIGUSR1'', and so on) or a
 signal number. The characters ``SIG'' may be omitted from the
 signal name. The command or block specifies code to be run when the
 signal is raised. If the command is the string ``IGNORE'' or
 ``SIG_IGN'', the signal will be ignored. If the command is
 ``DEFAULT'' or ``SIG_DFL'', the operating system's default handler
 will be invoked. If the command is ``EXIT'', the script will be
 terminated by the signal. Otherwise, the given command or block
 will be run. The special signal name ``EXIT'' or signal number zero
 will be invoked just prior to program termination. trap returns the
 previous handler for the given signal.

     Signal.trap(0, proc { puts "Terminating: #{$$}" })
     Signal.trap("CLD") { puts "Child died" }
     fork && Process.wait

 produces:

     Terminating: 27461
     Child died
     Terminating: 27460

```

–  
Avdi

Home: [http://avdi.org](http://avdi.org)  
Developer Blog: [http://avdi.org/devblog/](http://avdi.org/devblog/)  
Twitter: [http://twitter.com/avdi](http://twitter.com/avdi)  
Journal: [http://avdi.livejournal.com](http://avdi.livejournal.com)

---

<div class="post-metadata">

**Author:** ![sealedsun](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e68b1a/32.png) [@sealedsun](https://www.ruby-forum.com/u/sealedsun)\
**Post date:** [April 15, 2008, 2:59pm UTC](https://www.ruby-forum.com/t/win32-process-signals/134809/3 "2008-04-15T14:59:41Z")

</div>

Avdi G. wrote:

> ```
> Signal.trap(0, proc { puts "Terminating: #{$$}" })
> Signal.trap("CLD") { puts "Child died" }
> fork && Process.wait
> 
> produces:
> 
> Terminating: 27461
> Child died
> Terminating: 27460
> 
> ```

Yeah, i know. But this obviously doesn’t work with win32.

My traps don’t catch anything _gg_

ck

---

<div class="post-metadata">

**Author:** ![sealedsun](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e68b1a/32.png) [@sealedsun](https://www.ruby-forum.com/u/sealedsun)\
**Post date:** [April 19, 2008, 4:51am UTC](https://www.ruby-forum.com/t/win32-process-signals/134809/4 "2008-04-19T04:51:02Z")

</div>

On Tue, 15 Apr 2008 07:59:42 -0500, Christian K. wrote:

> Avdi G. wrote:
> 
> > ```
> > Signal.trap(0, proc { puts "Terminating: #{$$}" })
> > Signal.trap("CLD") { puts "Child died" }
> > fork && Process.wait
> > 
> > ```

[snip]

> Yeah, i know. But this obviously doesn’t work with win32.
> 
> My traps don’t catch anything _gg_

If you can’t find a more portable solution, look at Win32 events,  
starting  
with the CreateEvent function.
