www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - spawnProcess() not child?

reply "Bauss" <jj_1337 live.dk> writes:
Is there a way to spawn a process that won't be a child process, 
because I can't seem to kill any processes created with 
spawnProcess() It keeps giving me access denied for the processes 
and it's necessary for me to kill a process, compile it and then 
spawn it again.

Currently what I do is save the pid of the spawned process and 
then call kill() using that pid then calling dmd which compiles 
it again, but after first compilation and spawning of the process 
I cannot do it again unless I restart the process that's handling 
the compilation etc. so I would like to have the process that 
updates to be a seperate process from the compiled process.

This is my code.
void end() {
	if (lastPid)
		kill(lastPid);
}

void clear() {
	if (exists(processFolder)) {
		foreach (string name;
			dirEntries(processFolder, SpanMode.depth)) {
			remove(name);
		}
		rmdir(processFolder);
	}
}

void compile() {
	if (lastPid)
		end();
	clear();
	
	string[] cmd = ["dmd.exe", "-of" ~ processFile, "-m32"];
	foreach (string e; dirEntries(srcFolder, SpanMode.depth))
		cmd ~= e;
		
	auto pid = spawnProcess(cmd);
	wait(pid);
	
	lastPid = spawnProcess(processFile);
}

Then I call compile() for everytime I need to update.

I have been looking through various code in the documents and 
google etc. but I cannot seem to achieve what I want. Is there no 
simple way to create a process that isn't associated with any 
processes using spawnProcess?
Nov 01 2014
next sibling parent "Bauss" <jj_1337 live.dk> writes:
Is there nobody that knows a solution? :(
Nov 03 2014
prev sibling parent reply "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm gmx.net> writes:
On Sunday, 2 November 2014 at 00:59:43 UTC, Bauss wrote:
 Is there a way to spawn a process that won't be a child 
 process, because I can't seem to kill any processes created 
 with spawnProcess() It keeps giving me access denied for the 
 processes and it's necessary for me to kill a process, compile 
 it and then spawn it again.
Taking a blind guess: Could it be that the process has already exited, and the PID got recycled and assigned to a new process? Then you would try to kill that process instead of your spawned one, which would fail if it doesn't belong to you.
Nov 03 2014
parent reply "angel" <andrey.gelman gmail.com> writes:
The parent / child relationship always exists.
In POSIX OSs, you may ignore SIGCHLD signal (announcing child 
process death), so that in case of child process exit it will not 
become zombie, rather it will be disposed on the spot.
As a side note, in Linux, there exist a system call allowing 
process re-parenting, but it is intended for use in 
experimenting, rather than in normal use case.
Side note II, there is no real chance of wrapping PID numbers 
around in a reasonable time frame.
Nov 03 2014
parent reply Steven Schveighoffer <schveiguy yahoo.com> writes:
On 11/3/14 6:34 AM, angel wrote:
 The parent / child relationship always exists.
 In POSIX OSs, you may ignore SIGCHLD signal (announcing child process
 death), so that in case of child process exit it will not become zombie,
 rather it will be disposed on the spot.
 As a side note, in Linux, there exist a system call allowing process
 re-parenting, but it is intended for use in experimenting, rather than
 in normal use case.
 Side note II, there is no real chance of wrapping PID numbers around in
 a reasonable time frame.
From OP's code, he is on Windows. -Steve
Nov 03 2014
parent "Sean Kelly" <sean invisibleduck.org> writes:
On Monday, 3 November 2014 at 14:09:21 UTC, Steven Schveighoffer 
wrote:
 From OP's code, he is on Windows.
I believe on Windows you have to sort out some kind of permissions to terminate a process. No idea if std.process does this, but it sounds like probably not.
Nov 03 2014