Date: Wed, 30 Mar 2005 20:42:23 +0200 From: Florent Thoumie <flz@xbsd.org> To: "Michael C. Shultz" <ringworm01@gmail.com> Cc: freebsd-hackers@freebsd.org Subject: Re: the best form to wait the finish of execution of a child... Message-ID: <1112208143.33469.7.camel@cream.xbsd.org> In-Reply-To: <200503301025.57363.ringworm01@gmail.com> References: <a9e342b5050330101771e53d6f@mail.gmail.com> <200503301025.57363.ringworm01@gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
--=-av4fWDHRsPTLN1s8eXuc Content-Type: text/plain; charset=iso8859-15 Content-Transfer-Encoding: quoted-printable Le Mercredi 30 mars 2005 =E0 10:25 -0800, Michael C. Shultz a =E9crit : > On Wednesday 30 March 2005 10:17 am, zean zean wrote: > > Hi Hackers: > > > > Excuse for my badly English. which is the best form to wait the > > finish of execution of a child. > > > > My idea is: > > > > pid_t chilpid; > > > > while(childpid !=3D wait(&status)) > > ; > > > > Any aid to obtain the best way is very welcome. > > > > PD. Excuse my ignorance and I hope they can guide me. > > > > Bye and thanxs ;) > > _______________________________________________ > > freebsd-hackers@freebsd.org mailing list > > http://lists.freebsd.org/mailman/listinfo/freebsd-hackers > > To unsubscribe, send any mail to > > "freebsd-hackers-unsubscribe@freebsd.org" >=20 > Here is how I do it, likely someone will have a better way: >=20 > pid_t pid; >=20 > pid =3D fork(); > if( !pid ) > { > execl( "/bin/mkdir", "mkdir", "directory_name", 0 ); > } > wait( (int*)pid ); Something like this would be better I think : pid_t pid; int ret;=09 pid =3D fork(); if (pid < 0) { perror("fork"); /* exit(1); if you want */ } else if (pid =3D=3D 0) { if (execl("/bin/mkdir", "mkdir", "directory_name", 0 )) perror("execl"); } else { wait(&ret); /* plus return code handling, YMMV */ } =09 You need to check fork(2) return code or your wait(2) is useless. Don't mix pid_t with int just for the gain of one variable. I haven't played with this for some time, I guess it's correct. --=20 Florent Thoumie flz@xbsd.org --=-av4fWDHRsPTLN1s8eXuc Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (FreeBSD) iD8DBQBCSvMPMxEkbVFH3PQRAhn7AJ0WL8NEUY0s5Ruo+0MK2Yp/9btNQgCdHC5P RcNj+lwgZsiiUn8j3j6255U= =uSjs -----END PGP SIGNATURE----- --=-av4fWDHRsPTLN1s8eXuc--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1112208143.33469.7.camel>