- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Nice values for background processes
Operating System - HP-UX
1820619
Members
1839
Online
109626
Solutions
Forums
Categories
Company
Local Language
юдл
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
юдл
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-22-2002 12:51 PM
тАО08-22-2002 12:51 PM
Nice values for background processes
Ok, Here's the deal, I understand that executing processes in the background (with &) by default get a nice value of 24 instead of the standard 20..
But why is it that if I launch a process in the background within a shell script, this rule does not hold true?
For example:
$sleep 999 &
[1] 21398
$ps -elf|grep sleep|grep -v grep
1 S oracle 21398 20571 0 168 24 50db4540 16 49a9a100 14:49:56 pts/3 0:00 sleep 999
$
But, if I run the following script..
$cat sleeptest
sleep 9999 &
$./sleeptest
$ps -elf|grep sleep|grep -v grep
1 S oracle 21489 1 0 168 20 4fddbcc0 16 4dd28140 14:51:44 pts/3 0:00 sleep 9999
$
The nice value is now 20? Is this right? It must be, but can someone explain to me why?
But why is it that if I launch a process in the background within a shell script, this rule does not hold true?
For example:
$sleep 999 &
[1] 21398
$ps -elf|grep sleep|grep -v grep
1 S oracle 21398 20571 0 168 24 50db4540 16 49a9a100 14:49:56 pts/3 0:00 sleep 999
$
But, if I run the following script..
$cat sleeptest
sleep 9999 &
$./sleeptest
$ps -elf|grep sleep|grep -v grep
1 S oracle 21489 1 0 168 20 4fddbcc0 16 4dd28140 14:51:44 pts/3 0:00 sleep 9999
$
The nice value is now 20? Is this right? It must be, but can someone explain to me why?
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-22-2002 01:02 PM
тАО08-22-2002 01:02 PM
Re: Nice values for background processes
An HP White Paper titled "HP-UX 10.0 Process Management White Paper" states the following about process priority and nice:
All processes have a priority, set when the process is invoked and based on factors such as who is running the process (user, system) and whether the process is created in a time-share or real-time environment.
The nice command can be used to set a process to run at a lower priority than would be set by default. nice does not lower the priority of an already running process. nice is useful for running programs whose execution time is not critical.
For example, suppose you have a program, named numcrunch, that manipulates large arrays of data, but the data is not critical to your work at the moment. How long it takes for the program to manipulate the data is unimportant; more critical programs should have greater access to CPU resources. To run numcrunch as a low priority background process, type:
$ nice numcrunch &
Note that both Korn and C shells handle nice slightly differently: ksh automatically lowers priority of background processes by four; this behavior can be modified using the bgnice argument. If you specify nice from ksh, it executes /usr/bin/nice and lowers priority by ten.
If you specify nice from csh, it executes its built-in command and lowers priority by four; however, if you specify /usr/bin/nice, csh lowers priority by ten.
For details, see nice(1), ksh(1), csh(1), renice(1M), and nice(2) in the HP-UX Reference.
Hope this helps.
All processes have a priority, set when the process is invoked and based on factors such as who is running the process (user, system) and whether the process is created in a time-share or real-time environment.
The nice command can be used to set a process to run at a lower priority than would be set by default. nice does not lower the priority of an already running process. nice is useful for running programs whose execution time is not critical.
For example, suppose you have a program, named numcrunch, that manipulates large arrays of data, but the data is not critical to your work at the moment. How long it takes for the program to manipulate the data is unimportant; more critical programs should have greater access to CPU resources. To run numcrunch as a low priority background process, type:
$ nice numcrunch &
Note that both Korn and C shells handle nice slightly differently: ksh automatically lowers priority of background processes by four; this behavior can be modified using the bgnice argument. If you specify nice from ksh, it executes /usr/bin/nice and lowers priority by ten.
If you specify nice from csh, it executes its built-in command and lowers priority by four; however, if you specify /usr/bin/nice, csh lowers priority by ten.
For details, see nice(1), ksh(1), csh(1), renice(1M), and nice(2) in the HP-UX Reference.
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-23-2002 05:38 AM
тАО08-23-2002 05:38 AM
Re: Nice values for background processes
David,
your first example shows that the sleep command is executed along with the & sign directly from your shell. This means the PID of the shell is the parent process (PPID) of the sleep command. The shell, therefore, lowers the nice value, because the shell launches the sleep command. See Brant's explanation.
In your 2nd example, the sleep command is not launched by the shell but by the script 'sleeptest'. The shell launches the script 'sleeptest' using the nice value for normal interactive processes (because there is no & sign appended to './sleeptest'). 'sleeptest' itself is the parent process for the sleep command, but hasn't changed the nice value of the sleep command, despite of the & sign. So, the sleep command gets the nice value of its parent process ('slepptest'). As you can see, the PPID of the sleep command is no longer that of 'sleeptest'. That's because 'sleeptest' immediatly exited after launching the sleep command. Therefore, the PPID changed to 1 (init).
I guess, if you'd executed './sleeptest &', then also the sleep command would run with the nice value 24.
Only the shell renices jobs that are put into the background with the & sign. In the other cases (e.g. using scripts), you should explicitly use the nice commend for renicing.
your first example shows that the sleep command is executed along with the & sign directly from your shell. This means the PID of the shell is the parent process (PPID) of the sleep command. The shell, therefore, lowers the nice value, because the shell launches the sleep command. See Brant's explanation.
In your 2nd example, the sleep command is not launched by the shell but by the script 'sleeptest'. The shell launches the script 'sleeptest' using the nice value for normal interactive processes (because there is no & sign appended to './sleeptest'). 'sleeptest' itself is the parent process for the sleep command, but hasn't changed the nice value of the sleep command, despite of the & sign. So, the sleep command gets the nice value of its parent process ('slepptest'). As you can see, the PPID of the sleep command is no longer that of 'sleeptest'. That's because 'sleeptest' immediatly exited after launching the sleep command. Therefore, the PPID changed to 1 (init).
I guess, if you'd executed './sleeptest &', then also the sleep command would run with the nice value 24.
Only the shell renices jobs that are put into the background with the & sign. In the other cases (e.g. using scripts), you should explicitly use the nice commend for renicing.
no users -- no problems
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Learn About
News and Events
Support
© Copyright 2025 Hewlett Packard Enterprise Development LP