Gentoo Archives: gentoo-dev

From: Zac Medico <zmedico@g.o>
To: gentoo-dev@l.g.o
Subject: Re: [gentoo-dev] multiprocessing.eclass: doing parallel work in bash
Date: Sat, 02 Jun 2012 20:40:19
Message-Id: 4FCA79F4.4080204@gentoo.org
In Reply to: Re: [gentoo-dev] multiprocessing.eclass: doing parallel work in bash by Mike Frysinger
On 06/02/2012 12:54 PM, Mike Frysinger wrote:

> # @FUNCTION: redirect_alloc_fd > # @USAGE: <var> <file> [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@××××××××××××××××.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

Replies