Send signals to processes

D

diho

Hello,

I start a process with the "Runtime.getRuntime.exec("...")" command
and like to send a signal to this process. How can I do this, since
java.lang.Process does not provide an apropriate method ?
Is there any alternative to the "exec"-command to execute commands ?

Thanks for help,
diho
 
G

Gordon Beaton

Hello,

I start a process with the "Runtime.getRuntime.exec("...")" command
and like to send a signal to this process. How can I do this, since
java.lang.Process does not provide an apropriate method ?
Is there any alternative to the "exec"-command to execute commands ?

There is no alternative. You can have the child process tell you its
pid though, and use that to send it signals. For example you can use a
runner script like this one to get the pid of any process you run with
Runtime.exec():

#!/bin/sh

echo $$
exec "$@"


Now do this to run "myprog":

Runtime.getRuntime().exec("runner myprog arg1 arg2");

and read the pid as the first line of output.

To send a signal to the process, use something like this:

Runtime.getRuntime().exec("/bin/kill -INT " + pid);

/gordon
 

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,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top