How to forcely quit a process in java

Discussion in 'Java' started by ganesh_don, Mar 16, 2007.

  1. ganesh_don

    ganesh_don New Member

    Joined:
    Mar 9, 2007
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    0
    Buddies... Actually i executed wget unix command using Runtime.exec() method and got the process object,now i want to forcely quit the running process as its taking much time to compleate,and i dont want to wait till it compleates.so how cud i forcely quit a process(similar to typing ctrl c in the terminal).please kindly help me.Thanks in advance...........
     
  2. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in
    You'll need the process id of the process, then use kill -9 [pid] to kill the process.
     
  3. ganesh_don

    ganesh_don New Member

    Joined:
    Mar 9, 2007
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    0
    OK MR.pradeep its fine,actually i cant use kill command bcoz i dont know the process id,anyhow leave it, now tell me how do i know whether this process is compleated or not.sorry for the late reply my internet is down for few days........Thanks for ur previous reply..........
     
  4. ganesh_don

    ganesh_don New Member

    Joined:
    Mar 9, 2007
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    0
    buddies i myself found the solution to check whether the process is compleated or not:

    solution
    Code:
    try{
            Runtime rt = Runtime.getRuntime();
            Process p = rt.exec("some command");
            while(true)
            {
               
               try{
                 if(p.exitValue()==0)
                 {
                     System.out.println("process terminated");
                     break;
                 }
               }
              catch(Exception e)
              {
                System.out.println("process in execution..............");
              }
            
            }
            
            }
            
            catch(Exception e)
            {
                e.printStackTrace();            
            }
    if there is some other solution let me know...........
     
    Last edited by a moderator: Mar 21, 2007
  5. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in
    Cool dude!
     
  6. ganesh_don

    ganesh_don New Member

    Joined:
    Mar 9, 2007
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    0
    Thankyou dude........
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice