delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1999/02/28/12:34:09

From: Alain Magloire <alainm AT rcsm DOT ece DOT mcgill DOT ca>
Message-Id: <199902281734.MAA26602@mccoy2.ECE.McGill.CA>
Subject: Re: inetutils
To: djgpp-workers AT delorie DOT com
Date: Sun, 28 Feb 1999 12:34:02 -0500 (EST)
In-Reply-To: <Pine.SUN.3.91.990228144332.5950e-100000@is> from "Eli Zaretskii" at Feb 28, 99 02:43:58 pm
X-Mailer: ELM [version 2.4 PL25]
MIME-Version: 1.0
Reply-To: djgpp-workers AT delorie DOT com

Bonjour

> `spawn' *does* allow to redirect the standard handles of the child
> program, it just requires that the parent redirects its handles for
> that; the child then inherits those redirected handles.  Since the
> parent doesn't resume until the child exits, it doesn't need to worry
> about its standard handles during the time the child program runs.
> When the child does return, the parent simply restores its handles to
> previous values.
> 

Ho ! I see, clever.

> > However it is possible to do it on Windows but not with djgpp framework ?
> 
> Since the multitasking is provided by Windows (which *can* be called
> an operating systerm ;-), it is exactly like on Unix, except that the
> way I described to run programs asynchronously doesn't include
> inheritance of standard handles and environment variables, so these
> must be treated separately and specially (in this case only).

You've said that "start /m" will actually "fork" a process,
How about something like this, for windows, will that work ?
Note this is just pseudo-code. There is lot of race conditions, i.e signals
etc ...

inet_spawn (const char path, int fdmap[], int fdlen)
{
	int fd[3];
	int pid;

	/* save/redirect std */
	fd[0] = dup(FILENO_STDIN);
	fd[1] = dup(FILENO_STDOUT);
	fd[2] = dup(FILENO_STDERR);
	dup2(fdmap[0], FILENO_STDIN);
	dup2(fdmap[1], FILENO_STDOUT);
	dup2(fdmap[2], FILENO_STDERR);
	pid = spwan(P_NOWAIT, "start", "/m", path, NULL);

	/* bring std back */
	dup2(fd[0], FILENO_STDIN);
	dup2(fd[1], FILENO_STDOUT);
	dup2(fd[2], FILENO_STDERR);
	return pid;
}

-- 
au revoir, alain
----
Aussi haut que l'on soit assis, on est toujours assis que sur son cul !!!

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019