PATCH: waitpid in natPosixProcess.cc

Casey Marshall csm@gnu.org
Wed Apr 21 16:52:00 GMT 2004


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

>>>>> "Andrew" == Andrew Haley <aph@redhat.com> writes:

Andrew> Casey Marshall writes:
>> Attached is a simple patch that invokes waitpid if either the
>> process is destroy()ed or the C call to exec() fails.
>> 
>> This prevents Runtime.exec from spawning zombie processes if the
>> given command cannot be found, or if the process is killed. I
>> wasn't sure if it was appropriate to call waitFor instead, but
>> (AFAIK) calling waitpid in these two spots is safe.

Andrew> I think this is probably wrong, because you don't set
Andrew> hasExited in the Process.  With this patch, a subsequent call
Andrew> to Process::destroy will cause some other process that
Andrew> coincidentally has the same PID to be killed.

Yeah, I noticed that afterwards.

It is, at least, necessary to call waitpid when the exec fails in
startProcess, and only if the fork() succeeded. `hasExited' doesn't
matter in that case, since the caller will get an exception.

Revised patch attached.

Also: shouldn't there be a finalize method in this class, that
destroys and waits on the process?

- -- 
Casey Marshall || csm@gnu.org
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.7 <http://mailcrypt.sourceforge.net/>

iD8DBQFAhqZUgAuWMgRGsWsRAnvUAJ4gnByEhyOA/ZT9C74kdI6cRvSZ0QCeNNJY
0Of5SzU2OjjfpID1NPYUbtQ=
=+SZS
-----END PGP SIGNATURE-----
-------------- next part --------------
A non-text attachment was scrubbed...
Name: natPosixProcess.patch
Type: text/x-patch
Size: 556 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/java-patches/attachments/20040421/37a05199/attachment.bin>


More information about the Java-patches mailing list