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

B

Ben Myles

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 =3D getpid();
char monitor_buffer[100];
sprintf(monitor_buffer, "/usr/local/bin/monitor %i &", monitor_pid);
system(monitor_buffer);

Thanks!

Ben
 
E

Eric Hodel

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

Ara.T.Howard

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
===============================================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top