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 #{$$} &" } -- Eric Hodel - drbrain / segment7.net - http://segment7.net FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04