当前位置:网站首页>Process and planned task management

Process and planned task management

2022-07-27 01:41:00 Strange mushrooms

  • Process and plan task management outline
    • 1. Basic concepts
      • Program
      • process
        • Father child process
      • Threads
        • Single thread
    • 2. static state / Dynamic statistics of process and system load
      • 1.ps
      • 2. top
      • 3.jobs( Including some background operations )
      • 4.pstree
      • 5.pgrep
      • 6. Terminate the process
    • 3. Periodic tasks
  • Basic concepts ( Program process Threads )

    • 1. Program
      • The definition of program : Executable code or data stored on CD or hard disk , It's a static concept , Only load the program into memory , The system can only execute after allocating resources for it , This state of execution is called process
    • 2. process
      • Process definition : A process is a process of dynamic execution of a program , A program can create multiple processes , Complete tasks by consuming system resources , Is the basic unit of resources allocated by the operating system , Most processes are independent of each other , Each process has its own independent address space , Processes can create threads to complete more refined operations , Processes are safer than threads , If the process fails, it should be independent of each other and will not affect , And thread failure ,os When feedback to the process is detected , There may be something wrong .
      • The concept of parent-child process : The parent process affects the child process , There is a relationship between them , The child process is logically derived from the parent process , If the parent process exits , And one or more of its subprocesses is still running , These processes are called orphan processes , The orphan process will be init Process adoption , And by the init The process completes the status collection for it . If the child process exits the parent process and is too busy to withdraw the child process, a zombie process will occur , The zombie process is essentially dead, so you can't kill it , You need to kill its parent process to kill it
    • 3. Threads
      • Definition of thread : A thread is an instance in a process , Relying on the process , Shared process space address ,cpu Resources, etc , It should be that threads are not independent of each other, so a thread problem may affect all threads
      • Single thread concept : Single core and single thread can only execute one task at a time , When the task volume is large, it will cause congestion ,CPU At the micro level, the time to process threads is very short , It's called a time slice , In theory CPU Deal with tasks one by one , You can complete multithreaded tasks at your own speed .
  • static state / Dynamic statistics of process and system load (ps jobs top pgrep pstree)
    • 1.ps( View static process statistics )
      • ps -aux:( Briefly display the information of all processes in the system )(aux The detailed content  

        • -u: Output process information in user oriented format
        • -x: Display the output process information in user oriented format
        • -a: Display the information of all processes under the current terminal , Including other processes
      • ps -elf:( Display system process information in long format )(elf The detailed content

        • -e: Display all process information in the system
        • -l: Use long format to display process information
        • -f: Display process information in full format
    • 2. top( Dynamically view the status of the process and the load of the system )

      • 1.(15:51:20 up 3:41) Time of the system now System process running time
      • 2.(2 user) Two users
      • 3.(load average:0.0 0.01 0.05)CPU Average load value A minute Five minutes 15 Average load in minutes
      • 4.(Tasks) How many tasks are there
      • 5.(running) There are several running
      • 6.(sleeping) There are several ready
      • 7.(stopped) There are several stops
      • 8.(zombie) There are several zombie processes
      • 9. Using a digital 1 You can see all cpu The proportion of
        • 1. us: user cpu Proportion
        • 2.sy: System cpu Proportion
        • 3.ni: Priority scheduling occupies
        • 4.id: Free cpu
        • 5.wa:I/O Waiting for occupation
        • 6.hi: System interrupt occupancy
        • 7.si: Software interrupt occupancy
        • 8.st: Virtualization takes up
    • 3.jobs( View background processes )
      • 1.jobs -l( View all processes in the background and display pid)

      • ######( Some scattered knowledge points about the backstage )######
      • ctrl + z: Pause the current process and suspend in the background
      • &: Added at the end of the order , Indicates that the command is run in the background
      • fg: Turn the suspended background to the foreground to start
      • bg: Keep the process suspended in the background starting in the background
      • nohup xxxx &: Run the program in the background , However, closing the terminal does not affect the operation of the program
    • 4.pstree( List process information in a tree structure )

      • pstree -pua
        • -p: When using this option, you can list the corresponding PID Number
        • -u: Option to list the corresponding user names
        • -a: Select to list the complete commands
    • 5.pgrep( Query process information )
      • pgrep -l: Query the process with the specified name , And show their PID Number

      • pgrep-u: Query the specified user PID Number

      • pgrep-t: Query the processes allowed on a specific terminal
    • 6. Terminate the process (Kill ,killall,pkill)
      • 1.kill( Terminate the process adopt PID Number )
        • kill xxxx(PID Number ) Terminate the process
        • kil -9 xxxx(PID Number ) Force process termination
      • 2.killall( End process by process name )
        • killall xxxx( The name of the process ) Terminate the process with the specified process name
        • killall -9 xxxx( Process name ) Forcibly terminate the process with the specified process name
      • 3.pkill( Through the user to which the process belongs -u Or terminal -l The end of the process )
        • pkill -9 -u “ xxxx”( end xxxx The user's process )
        • pkill-9 -i “xxxxx”( end xxxx The process of the terminal )
  • Planning task management (at and crontab)
    • One time task setup

      • at [HH:MM] [yyyy-mm-dd]
      • Finally using ctrl+d end
    • Periodic task setup
    • crontab Schedule tasks through multiple directories and files , Different types of tasks are set by different configuration files
      • -e : Manually add recurring tasks

      • If you want to start some tasks automatically, you need to enter the configuration file to modify

      • -r: Delete configured recurring tasks
  • a key
    • Understand the concept of process thread , adopt Top Check the process , Observe for one minute, ten minutes 15 Minute load trend , Analyze the cause of the failure
    • Skillfully use ,ptree( The tree displays process information ),pgrep( Specify a name / User query process ),jobs( View background processes ),ps( Static view process )
    • Understand process termination Kill, How to exit gracefully
    • Set up scheduled tasks , Single task at And periodic tasks crontab, understand * * * * * , Setting of time sharing day, month and week
  • difficulty
     
    • ps/top SATAT Process type , Processing of the value of system load , And the commands of each query process , Format compilation of periodic tasks
  • Summary of notes
    • This chapter mainly understands the commands for viewing system process information (ps-elf ps-aux), And specify to view user processes (pgrep -u) And through the pgrep- i and kill The specified termination process is carried out in the form of combination , Set periodic tasks , Complete regular functions
  • Use Technology Association links
     
原网站

版权声明
本文为[Strange mushrooms]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/208/202207262240119798.html