• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
haifeng zhou
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Start it in a new Thread.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 17989
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
haifeng zhou
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks all, I will try
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 11852
185
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Personally I would have the Unix job started via a nohup process.

Note: I have not tried this, but I think it should work.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic