-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Mayank Jain wrote:
> waitpid(child, &status, 0);
> if(WIFEXITED(status))
> {
> printf("Child exited\n");
> break;
> }
.
.
> I've tried using WNOHANG in waitpid as waitpid(child, &status,
> WNOHANG) & this is the output i get
.
.
> an overkill (all i want to do is keep parent in non-blocking state,
> while looping for child's alive status).
Check for the waitpid() value 0 (which is returned when WNOHANG is used,
and no child has exited.)
in your code:
waitpid_result = waitpid(child, &status, WNOHANG);
if (waitpid_result && WIFEXITED(status))
{
printf("Child exited\n");
break;
}
should give you the expected results.
Note: Do take a look at your program logic here in scenarios where the
child does not exit normally. waitpid() will return the PID of the
child, but WEXITED() will not be true in such cases. Hence the parent
process (in your program) will go into an endles loop.
Manish
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFDrkAD9364pdQFFqARAsTgAJ0aqNPj1tKeOl7IBRENZTlimvDBfgCfS/Ox
s1LESo8V/Y13EKxrQkdtuIE=
=2hmG
-----END PGP SIGNATURE-----
_______________________________________________
ilugd mailinglist -- [email protected]
http://frodo.hserus.net/mailman/listinfo/ilugd
Archives at: http://news.gmane.org/gmane.user-groups.linux.delhi
http://www.mail-archive.com/[email protected]/