Results 1 to 9 of 9
  1. #1
    rgupta12 is offline Member
    Join Date
    Jan 2016
    Posts
    5
    Rep Power
    0

    Default Runtime.getRuntime().exec("kill -STOP + PID).waitFor()

    Any idea, this works on linux from terminal (it pauses a process)

    kill -STOP + 227222

    This does not work from JAVA code though? (the PID is correct)

    Runtime.getRuntime().exec("kill -STOP + PID).waitFor();

    However,

    Runtime.getRuntime().exec("kill + PID).waitFor() DOES work (kills the process)

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Runtime.getRuntime().exec("kill -STOP + PID).waitFor()

    Does the posted code compile without any errors?

    It shouldn't because of "s

    Please post the code that is being executed.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    rgupta12 is offline Member
    Join Date
    Jan 2016
    Posts
    5
    Rep Power
    0

    Default Re: Runtime.getRuntime().exec("kill -STOP + PID).waitFor()

    Quote Originally Posted by rgupta12 View Post
    Any idea, this works on linux from terminal (it pauses a process)

    kill -STOP + 227222

    This does not work from JAVA code though? (the PID is correct)

    Runtime.getRuntime().exec("kill -STOP + PID).waitFor();

    However,

    Runtime.getRuntime().exec("kill + PID).waitFor() DOES work (kills the process)

    Entire code - JSP page:

    <%@ page import="java.io.BufferedReader" %>
    <%@ page import="java.io.InputStreamReader" %>
    <%@ page import="java.util.StringTokenizer" %>
    <html>
    <head>
    <title>Sample Application JSP Page</title>
    </head>
    <body bgcolor=white>

    <table border="0">
    <tr>
    <td align=center>
    <img src="images/tomcat.gif">
    </td>
    <td>
    <h1>Pausing/Hanging Process using SIGSTOP</h1>

    </td>
    </tr>
    </table>
    <br><br>
    <%
    String pid = request.getParameter("pid");
    out.println("hanging ... pid = " + pid);
    try{
    Runtime.getRuntime().exec("kill -STOP" + pid).waitFor();
    }catch(Exception e){
    e.printStackTrace();
    }


    %>
    </body>
    </html>

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Runtime.getRuntime().exec("kill -STOP + PID).waitFor()

    Are there any messages return to the input or error streams from the Process?
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    rgupta12 is offline Member
    Join Date
    Jan 2016
    Posts
    5
    Rep Power
    0

    Default Re: Runtime.getRuntime().exec("kill -STOP + PID).waitFor()

    Quote Originally Posted by rgupta12 View Post
    Any idea, this works on linux from terminal (it pauses a process)

    kill -STOP + 227222

    This does not work from JAVA code though? (the PID is correct)

    Runtime.getRuntime().exec("kill -STOP + PID).waitFor();

    However,

    Runtime.getRuntime().exec("kill + PID).waitFor() DOES work (kills the process)
    ***
    NO Errors, no stack trace, nothing

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Runtime.getRuntime().exec("kill -STOP + PID).waitFor()

    The posted code does not show that it reads from the Process's streams so how do you know there are no messages?
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    rgupta12 is offline Member
    Join Date
    Jan 2016
    Posts
    5
    Rep Power
    0

    Default Re: Runtime.getRuntime().exec("kill -STOP + PID).waitFor()

    Let me know (if you have an idea) about what messages you want? and how to get them?
    Thanks

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Runtime.getRuntime().exec("kill -STOP + PID).waitFor()

    how to get them?
    Get the streams from the Process object and print them.
    If you don't understand my response, don't ignore it, ask a question.

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Runtime.getRuntime().exec("kill -STOP + PID).waitFor()

    First off, you really shouldn't have Java code in a JSP page like that.
    It should be in a servlet.

    In any case, create a String with the command you plan on using, and print that String to the screen, before executing it.
    I think you'll find it's not what you think it is.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Is there an alternative to Runtime.getRuntime().exec()
    By md_suzon in forum Advanced Java
    Replies: 5
    Last Post: 04-24-2013, 02:17 PM
  2. Runtime.getRuntime().exec() and pppd
    By mysticav in forum Networking
    Replies: 7
    Last Post: 02-15-2011, 07:44 PM
  3. Slow Output reading with Runtime.getRuntime().exec()
    By gmcouto in forum Advanced Java
    Replies: 8
    Last Post: 05-14-2010, 10:42 AM
  4. help with Runtime.getRuntime().exec
    By collin389 in forum AWT / Swing
    Replies: 3
    Last Post: 11-09-2009, 04:22 AM
  5. Replies: 6
    Last Post: 12-29-2008, 02:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •