How to run some c code for every real and forked ruby process

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 :wink:

    int monitor_pid = getpid();
    char monitor_buffer[100];
    sprintf(monitor_buffer, "/usr/local/bin/monitor %i &", monitor_pid);
    system(monitor_buffer);

Thanks!

Ben

No need for C.

BEGIN {
   system "/usr/local/bin/monitor #{$$} &"
}

···

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 :wink:

    int monitor_pid = getpid();
    char monitor_buffer[100];
    sprintf(monitor_buffer, "/usr/local/bin/monitor %i &", monitor_pid);
    system(monitor_buffer);

--
Eric Hodel - drbrain@segment7.net - http://segment7.net
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

does this work for forked children? i'm guessing not - but i'm maybe the
monitor program does that?

-a

···

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 :wink:

    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 #{$$} &"
}

--

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

===============================================================================