LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-27-2006, 01:37 PM   #1
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
process and child process in java


ok what i have is a process in java that is created and then has multiple commands written to it using a stream. so as this process gets written to it spawns child processes, and some of those child processes are large. some taking up to a half hour to run. i need to implement a method that will kill the current running child process (basically a cancel button). however according to java
Quote:
The subprocess is not killed when there are no more references to the Process object, but rather the subprocess continues executing asynchronously.
so it would seem that there is no way to keep track of a child process. however, when the java application is closed the child process is killed. so there is somthing in there that knows about the child process, it just seems like i cant get to it.

i know the ideal method would be to launch the child in its own process, however the system is already built and i do not really want to change more than i have to. so any ideas on killing this child process would be welcomed..

oh and this is in windows.
 
Old 03-27-2006, 04:33 PM   #2
95se
Member
 
Registered: Apr 2002
Location: Windsor, ON, CA
Distribution: Ubuntu
Posts: 740

Rep: Reputation: 32
What it means by that is that even if there are no more references to a process somewhere, it won't be stopped. I think it's just referring to a frequent question people may have concerning Java's garbage collection and the Process class. Typically, if there are no more references to an object in Java, that object is removed to free up memory. This is not true for the Process object, since a Process object, even if there are no more references to it, may still be doing useful work. If Java exits, it will kill all Process I guess, but if your program is still running, and the Process hasn't exited normally yet, and you haven't killed it, then it will stay alive (even if there are no references to it anywhere). This does not mean you can't kill it. Use the destroy method,
Quote:
destroy

public abstract void destroy()

Kills the subprocess. The subprocess represented by this Process object is forcibly terminated.
 
Old 03-27-2006, 04:38 PM   #3
95se
Member
 
Registered: Apr 2002
Location: Windsor, ON, CA
Distribution: Ubuntu
Posts: 740

Rep: Reputation: 32
Hrmmm, I get what your saying now, nvm.
 
Old 03-27-2006, 05:07 PM   #4
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Original Poster
Rep: Reputation: 45
Quote:
Hrmmm, I get what your saying now, nvm.
yeh.. actually after i had someone else here read the quote i posted i saw that it is not exactly a good example of what i am referring to..

anyhow, it now appears from some other reasearch, that once a child process is spawned from the current process, java does not track that sub process at all.. and even if i kill the process that i write the commands to, it still does not kill the child.. apparently for portability reasons they did not included any way to track child processes..

so i am going to end up rewriting a bunch of other code to reimplement this.. unless someone has a smart way to do this.. it was suggested to me to parse the pid out of a task list and kill that task.. however this seems even less portable than using Process..
 
Old 03-28-2006, 10:36 AM   #5
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Original Poster
Rep: Reputation: 45
ok.. well this is for the most part taken care of now. i ended up using the common method of just writing to the stream that process provides..

however now i have another problem. when this external program is inside a large loop, i cannot interrupt it by writing a ctrl-c to the process. however when i run it from console (not java), i can ctrl-c it anytime and it responds immediately..

i have no prior experience running this large of external program from java and i wonder if there are some little gotchas that i dont know about.. it would seem that the ?thread? that the external program is running in is so high priority that it will not respond to the ctrl-c.. however i do not see anyway to change the priority as it would be the OS that is controlling the external program.. ??

anyone
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how a father process know which child process send the signal SIGCHLD icoming Programming 10 07-20-2010 07:26 AM
How to kill a Child and all its subsequent child process in C shayer009 Programming 3 12-04-2007 12:40 AM
Child process state. rastadevil Programming 9 03-16-2006 01:38 PM
Killing a child process from another child marri Programming 6 10-01-2004 07:08 PM
Bash Scripting - child process affecting parent process mthaddon Linux - General 1 05-02-2004 01:19 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:23 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration