From: "Ara.T.Howard" Date: 2005-10-07T12:18:03+09:00 Subject: Re: how to run some c code for every real and forked ruby process On Fri, 7 Oct 2005, Eric Hodel wrote: > On Oct 6, 2005, at 5:20 PM, Ben Myles wrote: > >> I have some C code (shown below) which I want executed every time ruby >> runs (it spawns a monitoring script that monitors the ruby process). >> >> I tried placing the code in main.c, and this works fine at first >> glance. However, if I fork something from within ruby the newly forked >> process doesn't get monitored (which is also why I can't just write a >> simple bash ruby wrapper). >> >> Could someone point me to a function in the ruby source where I can >> insert the code so that it would be run once for both real processes >> and forked children? >> >> I'm no C programmer, so I'm a bit out of my league here ;-) >> >> int monitor_pid = getpid(); >> char monitor_buffer[100]; >> sprintf(monitor_buffer, "/usr/local/bin/monitor %i &", monitor_pid); >> system(monitor_buffer); > > No need for C. > > BEGIN { > system "/usr/local/bin/monitor #{$$} &" > } does this work for forked children? i'm guessing not - but i'm maybe the monitor program does that? -a -- =============================================================================== | email :: ara [dot] t [dot] howard [at] noaa [dot] gov | phone :: 303.497.6469 | Your life dwells amoung the causes of death | Like a lamp standing in a strong breeze. --Nagarjuna ===============================================================================