Send signals to processes

Discussion in 'Java' started by diho@ba-horb.de, Feb 19, 2004.

  1. Guest

    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
     
    , Feb 19, 2004
    #1
    1. Advertising

  2. On 19 Feb 2004 06:46:45 -0800, wrote:
    > 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

    --
    [ do not email me copies of your followups ]
    g o r d o n + n e w s @ b a l d e r 1 3 . s e
     
    Gordon Beaton, Feb 19, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. default
    Replies:
    3
    Views:
    473
    Shaomin
    Oct 24, 2003
  2. Jeff Rodriguez
    Replies:
    23
    Views:
    1,207
    David Schwartz
    Dec 9, 2003
  3. Sori Schwimmer
    Replies:
    1
    Views:
    395
    Alan Kennedy
    Oct 27, 2005
  4. Mário Lopes

    Traping signals on child processes

    Mário Lopes, Jun 2, 2008, in forum: Ruby
    Replies:
    12
    Views:
    303
    ara.t.howard
    Jun 3, 2008
  5. none
    Replies:
    9
    Views:
    349
Loading...

Share This Page