Date: Sun, 2 Jan 2000 11:23:36 +0200 (IST) From: Eli Zaretskii X-Sender: eliz AT is To: Steve Ball cc: djgpp AT delorie DOT com Subject: Re: system() hangs or returns incorrect value when child process killed In-Reply-To: <84m1ad$pbis$1@titan.xtra.co.nz> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Reply-To: djgpp AT delorie DOT com X-Mailing-List: djgpp AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk On Sun, 2 Jan 2000, Steve Ball wrote: > Does anyone know a workaround for this bug? I didn't see any bugs in what you describe. It's all expected behavior. > If the child process is killed using ^C or ^-Break, system() should return a > value with SIGINT in bits 8-17. Ideally, yes; but it doesn't always work. DOS is very inconsistent in this aspect, especially since many programs catch ^C and ^BREAK and do custom things before they exit. > 1. If the child process is a .COM file (such as CHOICE.COM), the return > value is zero. It depends on what the .COM program return when aborted. > 2. More importantly, if it is a DJGPP-compiled program, the return value is > 255 (as if the process had terminated by calling exit(255)). This is expected behavior for a DJGPP program, assuming that it does not install a handler for the signal SIGINT. If it does install a SIGINT handler, the result depends on what the handler returns (if it exits to DOS). > 3. If the command line is "DELTREE \SOMEDIR", killing the child process with > ^C hangs the DOS session (this works okay if entered from the shell). I don't think it hangs, I think it waits for the keyboard input. Try typing "n [Enter]" at that point, and see if the program continues to run. In general, aborting a program that reads the keyboard sometimes requires you to type some input before the program aborts, because aborting the program from within a DOS call (the one which reads the keyboard) is not always possible. > errno is not set in any of these cases `system' is only documented to set `errno' if it cannot run the child program. Aborting the child program is not documented, and is not supposed, to set `errno'. > I have posted this buf to the DJGPP bug list > (http://www.delorie.com/djgpp/bugs/show.cgi?000311) but, right now, I'm keen > to find a workaround... Please do not submit bug reports to the bug-tracker unless you are absolutely positive that you have found a bug in DJGPP. In particular, we cannot possibly repair any lossage that is caused by the OS or by non-DJGPP programs running on that OS. Please always post a bug report here before submitting it to the bug tracker. I spend a lot of time closing bug reports which aren't bugs at all, or aren't DJGPP bugs. > How can I tell if a child process was terminated (so the parent can > terminate too)? Please post more details about what you are trying to accomplish. It is hard to give intelligent advice without knowing the details. In general, pressing ^C while the child program runs delivers the signal SIGINT to its parent(s) as well, so the parent doesn't need to do anything to terminate: it will be aborted automatically once the child exits.