[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: GNU Parallel Bug Reports which shell is invoked (Was: why is paralle
From: |
Stephane Chazelas |
Subject: |
Re: GNU Parallel Bug Reports which shell is invoked (Was: why is parallel invoking a shell **by default** and associated bugs) |
Date: |
Sun, 31 May 2015 21:14:33 +0100 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
2015-05-31 16:22:15 +0200, Ole Tange:
> On Tue, May 26, 2015 at 9:39 AM, Stephane Chazelas
> <address@hidden> wrote:
>
> > The problem is that "called from a shell" is not very clear and
> > parallel doesn't (and often can't) always get it right.
> >
> > In most shells, the last command in an inline script is executed
> > in the same process (without forking a new process) (with bash,
> > only when there's one command...)
> >
> > $ bash -c "parallel 'readlink /proc/\$\$/exe;true' ::: 1"
> > /bin/zsh5 # my interactive shell
>
> Yikes. I did not know that some shells use exec if it is the only command.
Most shells do. Remember a shell is invoked in every
system("foo") or popen("bar"), you don't want it to spawn
unecessary processes if you can avoid it.
Executing the command in the same process helps reporting deaths
by signal accurately to the system() caller as well.
>
> > $ bash -c ":;parallel 'readlink /proc/\$\$/exe;true' ::: 1"
> > /bin/bash
>
> Though it is probably better to write 'true;' as that ought to work in
> all shells.
>
> And even better would be to append '&& true':
>
> zsh% ksh -c "true;parallel 'readlink /proc/\$\$/exe;true' ::: 1"
> /bin/zsh5
>
> zsh% ksh -c "parallel 'readlink /proc/\$\$/exe;true' ::: 1 && true"
> /bin/ksh93
[...]
Or you can use "; exit".
Again, that transforms a death by signal n to a exit(128+n) (and
wastes a process).
--
Stephane