[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] Simple syntax nice a subprocess in a pipeline?
From: |
Andy Chu |
Subject: |
Re: [Help-bash] Simple syntax nice a subprocess in a pipeline? |
Date: |
Mon, 1 Jul 2019 20:54:57 -0700 |
I would solve this problem with a script like this:
fun1() { ... }
mypipeline() {
fun1 | nice $0 fun2 | fun3
}
"$@" # run function $1 with args $2 .. N (can also be made more explicit)
Then invoke it with "myscript.sh mypipeline"
I use the same pattern to run a shell function with xargs (or find
-exec), if you use that.
I've been meaning to write a blog post about this pattern for awhile.
It also solves the errexit problem, where failure is ignored when you
probably don't want it to be. That is:
set -e
# using myfunc for its exit status, but internal failure is also ignored
if myfunc; then
echo true
fi
# solves that problem
if $0 myfunc; then
echo true
fi
Andy
On Mon, Jul 1, 2019 at 7:28 PM Peng Yu <address@hidden> wrote:
>
> Hi,
>
> I'd like to nice the process in which fun2 runs (fun2 is a bash
> function instead of an external command, so directly use `nice fun2`
> is not appropriate).
>
> fun1 | fun2 | fun3 ...
>
> I could get the PID in between the first "|" and the second "|", then
> renice that PID. But this is more cumbersome than the syntax of nicing
> an external program.
>
> Is there a convenient syntax to nice a subprocess in a pipeline? Thanks.
>
> --
> Regards,
> Peng
>