473,770 Members | 2,144 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

process.destroy () does not kill the subprocess

127 New Member
Dear All,

I have an issue with destroy() method of java.lang.Proce ss class. All what I am trying to do is, controlling the execution of one program through another. Let's say, Program B has to be executed conditionally through Program A based on the commands it gets from the user. Let's say, we have two inputs, "start" and "stop" to drive the Program B.

I have thought of various alternatives.

(1) Using Thread to control the execution of Program B. But then stopping a process means via a thread is not allowed as the related methods are deprecated (stop/suspend etc.,)
(2) Using ThreadGroup ( to have only one thread as its member) and calling 'destroy' on the group. But it again falls on the same track as every thread should be stopped before the destroy operation is attempeted.
(3) Process/ProcessBuilder via Runtime -- seems to be the better way to obtain a process reference and call destroy(), waitFor() etc., to control the spawned child process.


I went ahead with 3rd approach and all went fine till the spawning of the new child process. When the time came to stop the execution (ideally speaking, to stop! but practically destroying/killing the child process), it breaks! .

My main program (Program A) gives an information that the Program B stopped successfully (as I do store the process references in a Map and retrieve the same before destroying the process) and this operation succeeds. But it does NOT really reflect in reality and my child program still runs as if it was never interrupted. Looks like the child process gets disjoint with the parent process and hence the link gets cut between the two. I have to invoke my Program B via "cmd.exe /C java.exe ProgramB". I do use Windows XP and JRE 1.6.0_10 beta.

Program B is a java program which just keeps writing the date and time into a log file on an interval of 1 second. Program A has the main() method and gets the "threadName && start/stop" inputs from the user and retains the information into the Map. I am not dependent on my Program B's output and hence I don't invoke waitFor() and exitValue() methods.

If required I can post the program here.

Having been searching in the internet for a long time but nothing seems to be fruitful. Some says that it may be a bug with JVM. But I don't think so.

Few typical examples of this kind is, Tomcat catalina (startup.bat/shutdown.bat) and Quartz Job Scheduler -- they do get a command from the user 'start/stop' to fire an action!

Looks strange as the API does NOT guarantee the behavior as per the Specification. It says,

Expand|Select|Wrap|Line Numbers
  1. public abstract void destroy()  
  2.          Kills the subprocess. The subprocess represented by this Process object is forcibly terminated.   

Do I miss something here? Any suggestions would be of a great help!
Jun 9 '09 #1
6 16917
r035198x
13,262 MVP
Going back to your first alternative, just because the stop method is deprecated doesn't mean you can't stop a thread from executing. You can still use a flag to control a while loop that runs in the thread's run method. All you do is switch the flag when the stopping condition is reached. Once the run method ends, the thread will stop.
Jun 9 '09 #2
itsraghz
127 New Member
Hi r035198x,

Hope you are doing fine. Thanks for the reply!

Yes of course. You are right. Just because a method is deprecated does not mean that we can't/should not use. However, this usage is strictly NOT suggested by Sun itself as they are potentially dangerous (wrt the locks the objects might have acquired) Reference URL -> http://java.sun.com/j2se/1.5.0/docs/...precation.html.

I was about to have the other alternative you suggested. Like having a logical lock to control the execution. Let me test the other possibilities and get back.

Thanks.
Jun 9 '09 #3
r035198x
13,262 MVP
Read my reply again. I didn't say that you should use the stop method, I pointed out how to stop a thread without using the stop method.
Jun 9 '09 #4
itsraghz
127 New Member
Yes, that is what I also meant. Apologize if it was not reflected in the words.
Jun 9 '09 #5
r035198x
13,262 MVP
I see no need for pursuing all these other alternatives. You can stop a thread using the approach I posted above. It's also described in that link you posted above and suggested as best practice.
Jun 9 '09 #6
itsraghz
127 New Member
yes of course. but I felt proceeding with the process itself as I can get hold of the entire process so as to destroy/kill at once completely! Thus, have chosen this way.
Jun 9 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

5
7958
by: Natan | last post by:
Hi. I have a python script under linux where I poll many hundreds of interfaces with mrtg every 5 minutes. Today I create some threads and use os.system(command) to run the process, but some of them just hang. I would like to terminate the process after 15 seconds if it doesn't finish, but os.system() doesn't have any timeout parameter. Can anyone help me on what can I use to do this?
1
3151
by: Manfred Braun | last post by:
Hi All, I am writing a tool, which should monitor some exe-processes, which are not very solid. Th main function is to re-start them, if they hung, but this is complicated. I can detect things like no longer generating IO or such properties and I use WMI to do that. I am also looking for attached subprocesses, which are one of the system debuggers. I wrote a test-program, which creates a divide by zero error after some seconds. I can...
3
6499
by: elrondrules | last post by:
Hi Am new to python and need your help!! this is my code snip. within my python script I have the following commands.. <snip> import os
4
20782
by: Richard Rossel | last post by:
Hi Fellows, I have a problem with process termination. I have a python code that apache runs through a django interface. The code is very simple, first, it creates a process with the subprocess.Popen call, and afterwards, (using a web request) the python code uses the PID of the previously created process(stored in a db) and kills it with an os.kill call using the SIGKILL signal. The creation of the process is ok, apache calls the...
12
4536
by: bhunter | last post by:
Hi, I've used subprocess with 2.4 several times to execute a process, wait for it to finish, and then look at its output. Now I want to spawn the process separately, later check to see if it's finished, and if it is look at its output. I may want to send a signal at some point to kill the process. This seems straightforward, but it doesn't seem to be working. Here's my test case:
2
1192
by: John Nagle | last post by:
There doesn't seem to be any way to portably kill another process in Python. "os.kill" is Mac/Unix only. The "signal" module only lets you send signals to the current process. And the "subprocess" module doesn't have a "kill" function. Subprocess objects really should have a portable "interrupt" or "kill" function. They already have "poll" and "wait", which have to be implemented differently for different systems; that's the logical...
1
4756
by: Salim Fadhley | last post by:
Does anybody know of a python module which can do process management on Windows? The sort of thing that we might usually do with taskmgr.exe or process explorer? For example: * Kill a process by ID * Find out which process ID is locking an object in the filesystem * Find out all the IDs of a particular .exe file * Find all the details of a currently running process (e.g. given an
2
2512
by: =?Utf-8?B?WVhR?= | last post by:
Hello, In the parent process(A), run update function, and start the update process(B), in B process, kill A, then download and update files, then restart A. I want to know can the B process kill A process? Thank you
7
6237
by: Samuel A. Falvo II | last post by:
I have a shell script script.sh that launches a Java process in the background using the &-operator, like so: #!/bin/bash java ... arguments here ... & In my Python code, I want to invoke this shell script using the Subprocess module. Here is my code: def resultFromRunning_(command):
0
9618
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10101
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8933
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7456
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.