From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1Sav7T-0002V6-7G for garchives@archives.gentoo.org; Sat, 02 Jun 2012 20:40:19 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id C2FDCE06EE; Sat, 2 Jun 2012 20:39:59 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 6FF0CE0527 for ; Sat, 2 Jun 2012 20:39:18 +0000 (UTC) Received: from [192.168.26.5] (ip98-164-193-252.oc.oc.cox.net [98.164.193.252]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: zmedico) by smtp.gentoo.org (Postfix) with ESMTPSA id D65A51B402C for ; Sat, 2 Jun 2012 20:39:17 +0000 (UTC) Message-ID: <4FCA79F4.4080204@gentoo.org> Date: Sat, 02 Jun 2012 13:39:16 -0700 From: Zac Medico User-Agent: Mozilla/5.0 (X11; Linux i686 on x86_64; rv:12.0) Gecko/20120506 Thunderbird/12.0.1 Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-dev@lists.gentoo.org Reply-to: gentoo-dev@lists.gentoo.org MIME-Version: 1.0 To: gentoo-dev@lists.gentoo.org Subject: Re: [gentoo-dev] multiprocessing.eclass: doing parallel work in bash References: <201206011841.23302.vapier@gentoo.org> <201206021554.04552.vapier@gentoo.org> In-Reply-To: <201206021554.04552.vapier@gentoo.org> X-Enigmail-Version: 1.5pre Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Archives-Salt: f7651c85-30fc-49bf-a787-f24eb293eae0 X-Archives-Hash: 32b2c2c2b422e99f86f0fd63692e4320 On 06/02/2012 12:54 PM, Mike Frysinger wrote: > # @FUNCTION: redirect_alloc_fd > # @USAGE: [redirection] > # @DESCRIPTION: > # Find a free fd and redirect the specified file via it. Store the new > # fd in the specified variable. Useful for the cases where we don't care > # about the exact fd #. > redirect_alloc_fd() { > local var=$1 file=$2 redir=${3:-"<>"} > > if [[ $(( (BASH_VERSINFO[0] << 8) + BASH_VERSINFO[1] )) -ge $(( (4 << 8) + 1 )) ]] ; then > # Newer bash provides this functionality. > eval "exec {${var}}${redir}'${file}'" > else > # Need to provide the functionality ourselves. > local fd=10 > while :; do > if [[ ! -L /dev/fd/${fd} ]] ; then > eval "exec ${fd}${redir}'${file}'" && break > fi > [[ ${fd} -gt 1024 ]] && return 1 # sanity > : $(( ++fd )) > done > : $(( ${var} = fd )) > fi > } I launched up a GhostBSD livedvd to see what /dev/fd/ looks like on FreeBSD, and it seems to contain plain character devices instead of symlinks to character devices: [ghostbsd@livecd ~]$ uname -a FreeBSD livecd 9.0-RELEASE FreeBSD 9.0-RELEASE #0: Sun Jan 15 17:17:43 AST 2012 root@ericbsd.ghostbsd.org:/usr/obj/i386.i386/usr/src/sys/GHOSTBSD i386 [ghostbsd@livecd ~]$ ls -l /dev/fd/ total 0 crw-rw-rw- 1 root wheel 0, 19 Jun 2 20:15 0 crw-rw-rw- 1 root wheel 0, 21 Jun 2 20:15 1 crw-rw-rw- 1 root wheel 0, 23 Jun 2 20:15 2 -- Thanks, Zac