help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: native nice command


From: Peng Yu
Subject: Re: native nice command
Date: Wed, 2 Mar 2022 13:45:07 -0600

No. I am not trying to change the niceness of the current shell.

I am trying to change nices of pipeline or external commands, or any
shell function run in the background, called within a shell function.

Here are some examples. Remove "nice" you get the original code,
adding "nice" back you get the equivalent effect that I want. Do they
make sense?

function f() {
 nice cmd
}

function f() {
 nice cmd1 | nice cmd2
}

function f() {
nice cmd &
}

function f() {
f2  # f2 is a function, anything in it like the above examples should be niced
}

function f() {
f2  & # f2 is a function, do everything like the above example, and
nice the shell that runs f2. # shell variable or functions accessible
in f should be accessible in f2 as well.
}

On 3/2/22, Andreas Kusalananda Kähäri <andreas.kahari@abc.se> wrote:
> On Wed, Mar 02, 2022 at 06:34:03AM -0600, Peng Yu 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.
>>
>> --
>> Regards,
>> Peng
>
> Since the niceness value is something that is attached to a *process*
> and is inherited by its child processes, and since functions are
> run within the current shell process, you are looking for a way to
> temporarily increase the niceness value of the current shell, and
> then restore it to it's original value, without being a root user?
> Ordinarily, you have to bo root to decrease the niceness value of a
> process.
>
> You don't post any example code, but could we assume that you want
> something like the following?
>
>
>       foo () { echo 'running nicely'; var='ok'; }
>
>       unset -v ok
>       nice foo
>
>       printf 'Expecting "ok": "%s"\n' "$var"
>
> Could you provide an example that shows what you are working with and
> further explains what you need to do?
>
> --
> Andreas (Kusalananda) Kähäri
> SciLifeLab, NBIS, ICM
> Uppsala University, Sweden
>
> .
>


-- 
Regards,
Peng



reply via email to

[Prev in Thread] Current Thread [Next in Thread]