aspose file tools*
The moose likes Linux / UNIX and the fly likes aboue Runtime.getRuntime().exec() create process Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "aboue Runtime.getRuntime().exec() create process" Watch "aboue Runtime.getRuntime().exec() create process" New topic
Author

aboue Runtime.getRuntime().exec() create process

haifeng zhou
Greenhorn

Joined: Oct 30, 2009
Posts: 13
it run in Unix
Runtime.getRuntime().exec() will create child process to excute shell script
and if I kill parent process, the child process will aslo exit
so, does any way to prevent child process exit???

Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

Start it in a new Thread.


http://home.arcor.de/hirnstrom/bewerbung
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16057
    
  21

Stefan Wagner wrote:Start it in a new Thread.


However, this probably won't work if you kill the entire parent JVM, since that would kill all child threads. To avoid that, you'd probably need to launch a new OS process, not a new JVM process. These are some Unix system calls for that kind of stuff, but I'm not sure if pure Java can use them (I'm too lazy to RTFM). If not, however, you could always create a new shell process with a shell script that does it.


Customer surveys are for companies who didn't pay proper attention to begin with.
haifeng zhou
Greenhorn

Joined: Oct 30, 2009
Posts: 13
thanks all, I will try
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

Tim Holloway wrote:
Stefan Wagner wrote:Start it in a new Thread.


However, this probably won't work if you kill the entire parent JVM, since that would kill all child threads. To avoid that, you'd ...

To avoid that, you'd just not kill the parent JVM.
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11460
    
  94

Personally I would have the Unix job started via a nohup process.

Note: I have not tried this, but I think it should work.


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: aboue Runtime.getRuntime().exec() create process