[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

killing ruby program from C

Joe Van Dyk

6/1/2005 5:03:00 PM

Hi,

I need to start some Ruby programs from a C program. The C program
needs to be able to terminate the Ruby programs when it either exits
or some condition is met.

I tried:

#include <stdio.h>
#include <stdlib.h>
#include <signal.h>


int main()
{
system("ruby test.rb");

sleep(5);
if (killpg(0, SIGKILL) == -1)
perror("killpg");
printf("main program ending\n");
return 0;
}

Which seems to work fine on a non-ruby program (i.e. another C
program). But the Ruby program (a simple while-true loop that prints
stuff) doesn't exit when the C program does killpg.

Thoughts?


2 Answers

Joe Van Dyk

6/1/2005 5:31:00 PM

0

Fixed. If I fork, and then launch the ruby program via system() in
the child process, the killpg kills the ruby program.

On 6/1/05, Joe Van Dyk <joevandyk@gmail.com> wrote:
> Hi,
>
> I need to start some Ruby programs from a C program. The C program
> needs to be able to terminate the Ruby programs when it either exits
> or some condition is met.
>
> I tried:
>
> #include <stdio.h>
> #include <stdlib.h>
> #include <signal.h>
>
>
> int main()
> {
> system("ruby test.rb");
>
> sleep(5);
> if (killpg(0, SIGKILL) == -1)
> perror("killpg");
> printf("main program ending\n");
> return 0;
> }
>
> Which seems to work fine on a non-ruby program (i.e. another C
> program). But the Ruby program (a simple while-true loop that prints
> stuff) doesn't exit when the C program does killpg.
>
> Thoughts?
>


nobu.nokada

6/1/2005 11:37:00 PM

0

Hi,

At Thu, 2 Jun 2005 02:30:37 +0900,
Joe Van Dyk wrote in [ruby-talk:144243]:
> Fixed. If I fork, and then launch the ruby program via system() in
> the child process, the killpg kills the ruby program.

SIGKILL lets ruby skip even finalizations and END blocks. If
SIGTERM is ignored, try SIGSTOP, SIGTERM and SIGCONT.

--
Nobu Nakada