From owner-freebsd-hackers@FreeBSD.ORG Wed Mar 30 18:42:29 2005 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id B6A8016A4CE for ; Wed, 30 Mar 2005 18:42:29 +0000 (GMT) Received: from smtp.xbsd.org (xbsd.org [82.233.2.192]) by mx1.FreeBSD.org (Postfix) with ESMTP id 30FED43D45 for ; Wed, 30 Mar 2005 18:42:29 +0000 (GMT) (envelope-from flz@xbsd.org) Received: from localhost (localhost.xbsd.org [127.0.0.1]) by smtp.xbsd.org (Postfix) with ESMTP id E7EEB115F2; Wed, 30 Mar 2005 20:44:53 +0200 (CEST) Received: from smtp.xbsd.org ([127.0.0.1]) by localhost (srv1.xbsd.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 77706-05; Wed, 30 Mar 2005 20:44:44 +0200 (CEST) Received: from cream.xbsd.org (cream.xbsd.org [192.168.42.6]) by smtp.xbsd.org (Postfix) with ESMTP id 45C2C114BE; Wed, 30 Mar 2005 20:44:44 +0200 (CEST) From: Florent Thoumie To: "Michael C. Shultz" In-Reply-To: <200503301025.57363.ringworm01@gmail.com> References: <200503301025.57363.ringworm01@gmail.com> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="=-av4fWDHRsPTLN1s8eXuc" Date: Wed, 30 Mar 2005 20:42:23 +0200 Message-Id: <1112208143.33469.7.camel@cream.xbsd.org> Mime-Version: 1.0 X-Mailer: Evolution 2.2.1.1 FreeBSD GNOME Team Port X-Virus-Scanned: amavisd-new at xbsd.org cc: freebsd-hackers@freebsd.org Subject: Re: the best form to wait the finish of execution of a child... X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 30 Mar 2005 18:42:29 -0000 --=-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--