Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > macOS > nohup and nice

nohup and nice
Thread Tools
clarkgoble
Mac Elite
Join Date: Mar 2001
Location: Provo, UT
Status: Offline
Reply With Quote
Mar 27, 2003, 06:38 PM
 
I'd read somewhere that when combining nohup and nice you have to put the full pathname. For instance I have a shell script that runs a bunch of file checks. I have about 40 of them and I don't want a huge load on the system, so I run them with nice -15.

However if they find what they are looking for, they download it, which can take time. So I want them to continue running even if I log out.

What I've done is set up a cron file which runs my shell program. In my shell program I have

/usr/bin/nohup nice -15 [command]

Two questions. The first is if this is right. (I'm fairly sure it is) The second is more my inquisitive nature. Is it true that had I done

nohup nice -15 [command]

that the nice would be ignored? If so, why?
     
Rainy Day
Grizzled Veteran
Join Date: Nov 2001
Location: Oregon
Status: Offline
Reply With Quote
Mar 29, 2003, 02:59 PM
 
The first is if this is right. (I'm fairly sure it is)
No, it's only true if you're using the tcsh shell, but not for sh nor bash. Your script is probably using sh, yes?
Code:
--> sh sh-2.05a$ nohup nice -15 sleep 180& [1] 3590 sh-2.05a$ sending output to nohup.out bash bash-2.05a$ nohup nice -15 sleep 180& [1] 3592 bash-2.05a$ sending output to nohup.out tcsh tcsh:% nohup nice -15 sleep 180& [1] 3594 tcsh:% /usr/bin/nohup nice -15 sleep 180& [2] 3596 tcsh:% sending output to nohup.out ps -co pid,nice,command PID NI COMMAND 3589 0 sh 3590 15 sleep 3591 0 bash 3592 15 sleep 3593 0 tcsh 3594 0 sleep 3596 15 sleep
Notice that the only "sleep" job not running under nice -15 is job #3594, which was the tcsh:% nohup nice -15 sleep 180& command.

The second is more my inquisitive nature. Is it true that had I done

nohup nice -15 [command]

that the nice would be ignored? If so, why?
Probably has to do with the way the shell parses the command line.

For instance I have a shell script that runs a bunch of file checks. I have about 40 of them and I don't want a huge load on the system, so I run them with nice -15.

However if they find what they are looking for, they download it, which can take time. So I want them to continue running even if I log out.
Perhaps you should consider making these scripts startup script deamons which run even when no one is logged in, rather than as cron jobs?
     
warpmoon
Forum Regular
Join Date: Sep 2000
Location: The dark side of the moon
Status: Offline
Reply With Quote
Mar 29, 2003, 07:26 PM
 
Originally posted by clarkgoble:
I have about 40 of them and I don't want a huge load on the system, so I run them with nice -15.
Hmm, maybe it's just me, but you said that you didn't want the scripts to place a "huge load" on your system, right? But wouldn't using a priority of -15 let those scripts place a *higher* load on your computer?
     
Rainy Day
Grizzled Veteran
Join Date: Nov 2001
Location: Oregon
Status: Offline
Reply With Quote
Mar 30, 2003, 01:35 PM
 
Yes (from man nice):
Code:
nice runs utility at an altered scheduling priority. If an increment is given, it is used; otherwise an increment of 10 is assumed. The super- user can run utilities with priorities higher than normal by using a neg- ative increment. The priority can be adjusted over a range of -20 (the highest) to 20 (the lowest).
     
clarkgoble  (op)
Mac Elite
Join Date: Mar 2001
Location: Provo, UT
Status: Offline
Reply With Quote
Apr 1, 2003, 04:28 AM
 
Duh. Oops. Yeah. I have 15. My typo. (Damn, I've been doing a lot of those since I got engaged- my hint to OSX Hints had a bunch as well)

Anyway, brief question. Someone suggested a startup script rather than a cron job. Why? Doesn't cron call the script whether I'm logged in or not? Why go to all the trouble of putting stuff in /Library/StartupItems, putting together a plist and so forth.

I know it's not too hard. (The following shows how)

http://www.opendarwin.org/documentat...rter_HOWTO.php

It does seem like a bit of overkill when cron works well, especially with Cronnix to help out.
( Last edited by clarkgoble; Apr 1, 2003 at 04:39 AM. )
     
Rainy Day
Grizzled Veteran
Join Date: Nov 2001
Location: Oregon
Status: Offline
Reply With Quote
Apr 4, 2003, 02:51 PM
 
Someone suggested a startup script rather than a cron job. Why?
The choice is somewhat arbitrary, but there are differences. A startup script is well suited for tasks which should start when the system starts, and run continuously in the background. A cron job, on the other hand, is intended for tasks which need to be run every so often, but which don't run continuously. The task you described, as i understand it, seemed best suited as a startup script.

Just beware that there is some overhead in running cron jobs, and ensure that you don't spawn multiple concurrent copies of your script if one will do.
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 07:54 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,