What is "Nice" ?

Discussion in 'macOS' started by brbubba, Feb 27, 2007.

  1. brbubba macrumors 6502

    brbubba

    Joined:
    May 20, 2006
    #1
    Could someone please explain to me, in laymen's terms what "nice" is. I am looking at my CPU activity monitor and it is saying around 30% is being used by "Nice." I looked it up in help and this is what I got, "For more information on "nice" processes, see the man page. Open Terminal, located in Applications/Utilities, and enter "man nice"."

    So I opened a terminal and looked at the man page and this is what I got,

    NAME
    nice -- execute a utility with an altered scheduling priority

    SYNOPSIS
    nice [-n increment] utility [argument ...]

    DESCRIPTION
    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).

    Needless to say, help wasn't much help at all.
     
  2. Blubbert macrumors 6502

    Joined:
    Nov 1, 2006
    #2
    As is my understanding, the nice command is a way to make programs use more or less CPU time. It would be useful if you have a processor intensive program, but dont want it to hog all the processor.
     
  3. VoidBoi macrumors regular

    Joined:
    Feb 5, 2007
    Location:
    Australia
    #3
    The 'nice' tool is used to run programs with different execution priorities.

    A 'niced' program can run with a higher or lower cpu priority than normal, for example, background processes can be set not to take over your CPU by giving them a positive nice value, and programs that are more important (such as DVD burning software), can be given CPU priority by giving them negative nice values.
     
  4. spicyapple macrumors 68000

    spicyapple

    Joined:
    Jul 20, 2006
    #4
    "Nice" is pleasant; agreeable; satisfactory or fine; subtle as in 'the gentleman was nice to my mom' or 'a nice distinction' Duh! :)


    In computer terminology, "nice" is pronounced "niece", so that helps to distinguish the word from the first definition. The nice command allows you to reduce CPU cycles to a particular app (thread).

    In Terminal, type: renice +20 [pid]
    where pid is the process id number; the number OSX assigns to each running app. You can usually find the number by typing top in Terminal or open Activity Monitor.

    Plus+ numbers (+1 to +20) reduce CPU priority, accordingly. So a pid of +20 is given less CPU time than a pid of +1. It also goes in reverse down to -20 (which means the app is given the highest CPU priority) You need to be logged into Super User mode to lower pid numbers.
     
  5. Westside guy macrumors 601

    Westside guy

    Joined:
    Oct 15, 2003
    Location:
    The soggy side of the Pacific NW
    #5
    I have never ever heard anyone pronounce "nice" in this way; and I've been working alongside Unix admins for lots o' years now. I think someone's been yankin' your chain. :D

    Nice rhymes with ice.
     
  6. brbubba thread starter macrumors 6502

    brbubba

    Joined:
    May 20, 2006
    #6
    Ok I think I am getting more confused. I understand computers very well on a macroscopic level, and don't understand them at all on a microscopic level, or in this case programming and code execution. Nor do I ever care to...

    Maybe we should break this down. Ok so % User I assume is user run applications and how much CPU they take up. % System I assume is the cpu thats being used for system processes. And % Idle is CPU not in use. So what the heck is % Nice? If 40% of the cpu is in use for Nice, what is it doing? Why is Nice taking up that much CPU?
     
  7. ElectricSheep macrumors 6502

    ElectricSheep

    Joined:
    Feb 18, 2004
    Location:
    Wilmington, DE
    #7
    That's probably not the greatest example, because DVD burning software is going to utilize threads which operate in the Real-Time priority band. Provided the software was written with this in mind, altering its 'nice' value won't affect the burn.

    There are four priority bands used by the Mach scheduler (in increasing order of priority): Normal, System High, Kernel, and Real-Time.

    Normal applications run in either Normal or System High priority. These are the applications you can use nice(1) or renice(8) on to change their priority. Obviously, applications which are given System High priority will have the privilege of being considered first when it comes time to schedule jobs on the CPU; they still have to take a back seat to Kernel and Real-Time jobs.

    Kernel priority is reserved for threads which run inside of the Kernel. Things like I/O drivers for external devices run with Kernel priority.

    Real-Time priority is just like it sounds: jobs that run in real-time are guaranteed to have time on the processor within a certain timeframe (as long as its request is reasonbly sane). If your software needs to run for 3000 cycles during the next 7000 cycles, real-time priority will try to make this possible sacrificing Normal, System High, and even Kernel priority jobs to do it. Burning a CD or DVD is a good example of a job that needs to have Real-Time priority. The laser burning the disc cannot be stopped in the middle of a burn; if your application doesn't feed data to the drive in a timely manner the burn will be corrupted. Audio playback is another real-time application.
     
  8. Westside guy macrumors 601

    Westside guy

    Joined:
    Oct 15, 2003
    Location:
    The soggy side of the Pacific NW
    #8
    I think it's worth pointing out that "nice" is more useful in a multi-user environment than on a single-user box. It can help keep one person's long, cpu-intensive task from adversely impacting other users' jobs (well, too much anyway).
     
  9. VoidBoi macrumors regular

    Joined:
    Feb 5, 2007
    Location:
    Australia
    #9
    Very interesting, thanks for that info. :)
     
  10. alfogator macrumors member

    Joined:
    Nov 3, 2005
    Location:
    Florence, Italy
    #10
    You can think of User and Nice as the same thing, so the amount of resources used do not change. What changes is the way this impacts other system activities.

    If you run a process that use, say, 100% of your cpu will leave no spare resources available, so if you launch another process that uses up 100% as well they both will contend for the available resources so each process will slow down the other one and they both will run at half speed.
    'Nice' cpu time on the other hand is allocated only if available, so in the same example, if you run a niced process that consumes 100% of cpu resources and then a 'user' process that uses the same 100% this second process won't be slowed down.

    You could sum it all up by saying that user/system cpu time slows down your machine if you want to do something else at the same time, while nice cpu time doesn't.

    This is a broad generalization. Also remember that cpu time is accounted by cpu, so if your system is dual core you have a total of 200% to spend, or 400% on a quad core.
     
  11. yellow Moderator emeritus

    yellow

    Joined:
    Oct 21, 2003
    Location:
    Portland, OR
    #11
    I have to agree with this statement. I have never heard, nor have I ever uttered "nice" in any other way than expected. Either that, or there's been a lot of messed up solaris guys working with me. ;)
     
  12. Westside guy macrumors 601

    Westside guy

    Joined:
    Oct 15, 2003
    Location:
    The soggy side of the Pacific NW
    #12
    Well, "messed up" and "Solaris guys" kind of go hand in hand. :D I kid, I kid...

    (although enabling telnet by default in this day and age IS kind of messed up; but that's Sun's fault, not your coworkers)
     
  13. yellow Moderator emeritus

    yellow

    Joined:
    Oct 21, 2003
    Location:
    Portland, OR
    #13
    Ah telnet.. Last time I used it, it was to connect to a printer.
     
  14. yellow Moderator emeritus

    yellow

    Joined:
    Oct 21, 2003
    Location:
    Portland, OR
    #14
    Speak of the devil.. :D

     
  15. princealfie macrumors 68030

    princealfie

    Joined:
    Mar 7, 2006
    Location:
    Salt Lake City UT
    #15
    Well, we can eliminate one thing, "nice" is not ice. :p
     
  16. mkrishnan Moderator emeritus

    mkrishnan

    Joined:
    Jan 9, 2004
    Location:
    Grand Rapids, MI, USA
    #16
    I love nices to pieces! Hey, according to that post above, that should rhyme, dammit! :(
     
  17. Westside guy macrumors 601

    Westside guy

    Joined:
    Oct 15, 2003
    Location:
    The soggy side of the Pacific NW
    #17
    :D

    Yeah, seeing that vulnerability announcement is the only reason I knew about Solaris' default install having telnet enabled. It just seems like such a blazingly stupid idea - there has to be some obscure reason they haven't turned it off by default...?
     
  18. colocolo macrumors 6502

    Joined:
    Jan 17, 2002
    Location:
    Santiago, Chile
    #18
    Or maybe he hangs around Scottish admins only...:D
     
  19. yellow Moderator emeritus

    yellow

    Joined:
    Oct 21, 2003
    Location:
    Portland, OR
    #19
    remote syslogging maybe.
     

Share This Page