[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: native nice command
From: |
Andy Chu |
Subject: |
Re: native nice command |
Date: |
Wed, 2 Mar 2022 11:51:56 -0500 |
On Wed, Mar 2, 2022 at 7:47 AM Peng Yu <pengyu.ut@gmail.com> wrote:
> Hi,
>
> Normally nice is an external program. Is it possible to make it a
> builtin, so that when a bash function is called, any external commands
> called by the function will be niced? If a function is called to run
> in the background, that background bash process is also niced? Thanks.
>
You can invoke nice on shell recursively, so It doesn't need to be a
builtin. (A nice values are inherited.) Here's the analogous issue with
xargs invoking shell functions:
http://www.oilshell.org/blog/2021/08/xargs.html#xargs-can-invoke-shell-functions-with-the-0-dispatch-pattern
Sample code:
https://github.com/oilshell/blog-code/tree/master/xargs
This is also useful with sudo invoking a shell function, etc. Often I have
a function calls _mywork and then define
mywork() { sudo $0 _mywork "$@"; }
Andy