This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

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

 
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???

 
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.
 
Bartender
Posts: 19726
92
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.
 
author and jackaroo
Marshal Commander
Posts: 12218
279
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
Boost this thread!