This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Linux / UNIX and the fly likes how to wait for non-child PID Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "how to wait for non-child PID" Watch "how to wait for non-child PID" New topic

how to wait for non-child PID

Isha Mackker

Joined: Oct 18, 2005
Posts: 29
Hi All,

I have written a shell script to update my web application, i.e. executing the shell script automatically stops the JBoss, replaces old ear file with new ear file and then start the JBoss.

I want the script to wait for the JBoss to stop and then start replacing the ear. I tried using wait $PID, extracting PID as:

PID=`ps -ef | grep '' | tr -s " " | cut -d" " -f2`
PID=`echo $PID | cut -d" " -f1`

where is another script to stop the JBoss and then calling the wait as:

wait $PID

the issue with this is that it says: line 8: wait: pid 4215 is not a child of this shell.

Please help.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15950

For the most part, it's not a good idea to attempt to consort with threads in a process unrelated to your own. Among other things, they may be running on a seperate CPU, in a separate address space or be in some other way not part of the same universe as your process.

However, a bigger question is "why stop JBoss?" One of the features that JBoss excels at is on-the-fly app updating. In most cases, it's sufficient to simply deploy a new copy of your webapp and JBoss will shut down the old copy and start the new one. And it takes a lot less time than restarting the entire app container.

Customer surveys are for companies who didn't pay proper attention to begin with.
Isha Mackker

Joined: Oct 18, 2005
Posts: 29
Yes, thats very true. I need not restart the JBoss.
Anyhow, to make the script wait, I can use this:
sleep 10s
this will make the script wait for 10 secs where 's' is a suffix to indicate seconds.
I agree. Here's the link:
subject: how to wait for non-child PID
Similar Threads
Get the UNIX process ID of the java program
Signal Handling
ProcessBuilder and Process
How to get processId of calling process in Java
Eclipse plugin for JBoss