zoukankan      html  css  js  c++  java
  • A quick renice command rescheduled the upgrade to a lower priority and I was back to surfing in no time.

     https://www.nixtutor.com/linux/changing-priority-on-linux-processes/

    Changing Priority on Linux Processes

    What is Priority and Why Should I Care?

    When talking about processes priority is all about managing processor time. The Processor or CPU is like a human juggling multiple tasks at the same time. Sometimes we can have enough room to take on multiple projects. Sometimes we can only focus on one thing at a time. Other times something important pops up and we want to devote all of our energy into solving that problem while putting less important tasks on the back burner.

    In Linux we can set guidelines for the CPU to follow when it is looking at all the tasks it has to do. These guidelines are called niceness or nice value. The Linux niceness scale goes from -20 to 19. The lower the number the more priority that task gets. If the niceness value is high number like 19 the task will be set to the lowest priority and the CPU will process it whenever it gets a chance. The default nice value is zero.

    By using this scale we can allocate our CPU resources more appropriately. Lower priority programs that are not important can be set to a higher nice value, while high priority programs like daemons and services can be set to receive more of the CPU’s focus. You can even give a specific user a lower nice value for all of his/her processes so you can limit their ability to slow down the computer’s core services.

    Checking the Priority of Running Processes

    The easiest way to get a quick picture of what the current niceness priority on a process is to open up the top processes with:

    top

    top
     q 
     h
    ps -o pid,comm,nice -p 123

    Setting priority on new processes

    At this point you are probably wondering how you can set your own priority levels on processes. To change the priority when issuing a new command you do nice -n [nice value] [command]:

    nice -n 10 apt-get upgrade
    

    This will increment the default nice value by a positive 10 for the command, ‘apt-get upgrade’ This is often useful for times when you want to upgrade apps but don’t want the extra process burden at the given time. Remember a positive number is gives less priority for a process.

    renice 10 -p 21827
    

    This will increment the priority of the process with an id of 21827 to 10.

    Note: Only root can apply negative nice values.

    Setting Priority on Existing Processes

    Obviously at some point you are going to want to alter the nice value of something that is already running. Just the other day I was doing an upgrade to Ubuntu Jaunty and Firefox started to become unusably slow. A quick renice command rescheduled the upgrade to a lower priority and I was back to surfing in no time.

    To change the priority of an existing process just do renice [nice value] -p [process id]:

    renice 10 -p 21827
    

    This will increment the priority of the process with an id of 21827 to 10.

    Note: Only root can apply negative nice values.

    Setting Permanent Priority on all Processes for a Specific User

    Sometimes it is helpful to give specific users lower priority than others to keep system resources allocated in the proper places like core services and other programs.

    You can set the default nice value of a particular user or group in the /etc/security/limits.conf file.

    /etc/security/limits.conf
    

    It uses this syntax: [username] [hard|soft] priority [nice value]

    backupuser hard priority 1
     1 Fields Management for window 1:Def, whose current sort field is %CPU
     2    Navigate with Up/Dn, Right selects for move then <Enter> or Left commits,
     3    'd' or <Space> toggles display, 's' sets sort.  Use 'q' or <Esc> to end!
     4 
     5 * PID     = Process Id
     6 * USER    = Effective User Name
     7 * PR      = Priority
     8 * NI      = Nice Value
     9 * VIRT    = Virtual Image (KiB)
    10 * RES     = Resident Size (KiB)
    11 * SHR     = Shared Memory (KiB)
    12 * S       = Process Status
    13 * %CPU    = CPU Usage
    14 * %MEM    = Memory Usage (RES)
    15 * TIME+   = CPU Time, hundredths
    16 * COMMAND = Command Name/Line
    17   PPID    = Parent Process pid
    18   UID     = Effective User Id
    19   RUID    = Real User Id
    20   RUSER   = Real User Name
    21   SUID    = Saved User Id
    22   SUSER   = Saved User Name
    23   GID     = Group Id
    24   GROUP   = Group Name
    25   PGRP    = Process Group Id
    26   TTY     = Controlling Tty
    27   TPGID   = Tty Process Grp Id
    28   SID     = Session Id
    29   nTH     = Number of Threads
    30   P       = Last Used Cpu (SMP)
    31   TIME    = CPU Time
    32   SWAP    = Swapped Size (KiB)
    33   CODE    = Code Size (KiB)
    34   DATA    = Data+Stack (KiB)
    35   nMaj    = Major Page Faults
    36   nMin    = Minor Page Faults
    37   nDRT    = Dirty Pages Count
    38   WCHAN   = Sleeping in Function
    39   Flags   = Task Flags <sched.h>
    40   CGROUPS = Control Groups
    41   SUPGIDS = Supp Groups IDs
    42   SUPGRPS = Supp Groups Names
    43   TGID    = Thread Group Id
    44   ENVIRON = Environment vars
    45   vMj     = Major Faults delta
    46   vMn     = Minor Faults delta
    47   USED    = Res+Swap Size (KiB)
    48   nsIPC   = IPC namespace Inode
    49   nsMNT   = MNT namespace Inode
    50   nsNET   = NET namespace Inode
    51   nsPID   = PID namespace Inode
    52   nsUSER  = USER namespace Inode
    53   nsUTS   = UTS namespace Inode
  • 相关阅读:
    多测师讲解app测试 _app原理图解_高级讲师肖sir
    多测师讲解 app_模拟器的端口号_高级讲师肖sir
    多测师讲解appium _开启注意点_高级讲师肖sir
    多测师讲解app _xpath插件_高级讲师肖sir
    多测师讲app测试 _appium实战(1)_高级讲师肖sir
    多测师讲解app测试 _ADB常用的指令_高级讲师肖sir
    jmeter分布式测试
    常用命令
    Linux安装pycharm
    请求头信息介绍
  • 原文地址:https://www.cnblogs.com/rsapaper/p/6238781.html
Copyright © 2011-2022 走看看