In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Linux/Centos7 system management processes and scheduled task management view processes-static and dynamic view control processes-conditions and all at one-time task settings crontab periodic task settings I. relationship between programs and processes (1) concept
Program: executable code and data stored in hard disk, CD, etc., belonging to statically saved code.
Process: program code that runs in CPU and memory, belonging to dynamically executed code
(2) how to understand the concepts of applications, processes and threads and contact applications-factory processes-workshop threads-workers
An application can contain one or more processes, a process contains one or more threads, and a thread is the smallest unit that performs an operation.
Ps: corresponding to high concurrency processing = = using multithreaded operations
2. Process-related commands (1) View process information ps
Ps command-- not Photoshop!
The man manual describes its function as follows: "displays information about a selection of the active processes. If you want a repetitive update of the selection and the displayed information, use top (1) instead."
It means to display information about the selection of active processes. If you want to update the selected and displayed information repeatedly, use top (the top here also views the information of the process, but dynamically, which will be described below)
(2) format of ps command
Ps [options] [parameters]
I selected some of the commonly used cases given in the man manual to demonstrate and describe:
-aux: "-" can be omitted to view each process in the system that uses BSD syntax rules
-elf: it means to view every process in the system that uses standard syntax, and "-" cannot be omitted.
Examples are as follows:
[root@lokott ~] # ps aux / / ps-aux is the same USER PID% CPU% MEM VSZ RSS TTY STAT START TIME COMMANDroot 1 0.00.4 210140 4864? Ss 14:23 0:01 / usr/lib/systemd/systemd-- switched-root-- system-- deserialize 21root 2000? S 14:23 0:00 [kthreadd] root 3 0.0 0.0 00? S 14:23 0:00 [ksoftirqd/0] root 5 0.0 0.0 00? S
< 14:23 0:00 [kworker/0:0H]root 6 0.0 0.0 0 0 ? S 14:23 0:00 [kworker/u256:0]root 7 0.0 0.0 0 0 ? S 14:23 0:00 [migration/0]root 8 0.0 0.0 0 0 ? S 14:23 0:00 [rcu_bh]root 9 0.0 0.0 0 0 ? R 14:23 0:00 [rcu_sched]... 解释:PID表示进程ID,%CPU表示CPU使用率,%MEM表示内存使用率,TTY表示终端,STAT表示的是状态:S 是sleep可中断,s表示父进程, pgrep -U root |wc -l >/ opt/ps.txtat > job 1 at Tue Nov 12 17:35:00 2019 [root@lokott ~] # cat / opt/ps.txt / / unable to see cat: / opt/ps.txt: no file or directory [root@lokott ~] # atq1 Tue Nov 12 17:35:00 2019 a root [root@lokott ~] # at 17:34 2019-11-12at > echo "123 "> 1.txtat > job 2 at Tue Nov 12 17:34:00 2019 [root@lokott ~] # atq / / View one-time task commands 1 Tue Nov 12 17:35:00 2019 a root2 Tue Nov 12 17:34:00 2019 a root [root@lokott ~] # ls1.txt note template document Desktop anaconda-ks.cfg Shell Video download initial-setup-ks.cfg Public Picture Music [root@lokott ~] # cat 1.txt 123 [root@lokott ~] # atrm 1 / / Delete outstanding tasks [root@lokott ~] # atq [root@lokott ~] # atrm 1 / / deleted and deleted Completed tasks cannot delete Cannot find jobid 1 again
The serial number is fixed, not dynamic, in order to avoid erroneous deletion when deleting tasks in multiple terminals.
(2) periodically scheduled task configuration-crontab command
Crontab commands (important)-scheduled tasks (repeat user-specified command operations according to pre-set time periods), as described in the man manual: crontab-maintains crontab files for individual users
Crontab-e [- u]-l--list-r--remove owned
The writing format is time-sharing, day, month and week command, and the write format is shown in the / etc/crontab file below
Where * represents any time in this range,-indicates continuous time
, indicates a discontinuous point in time, / represents a frequency
My understanding of this command is "private customization". This command can be used to store a scheduled task tabulation file, and can be used to delete (- r) and view (- l) the settings (- e) and view (- l) of periodic scheduled tasks. Examples are as follows:
[root@lokott ~] # which crontab / / View the location of the crontab command / usr/bin/crontab [root@lokott ~] # cat / etc/crontab / / View the configuration file information of the command SHELL=/bin/bashPATH=/sbin:/bin:/usr/sbin:/usr/binMAILTO=root# For details see man 4 crontabs / / the file is written in the format of-- time-sharing, day, month and week # Example of job definition:#.-- -minute (0-59) # |.-hour (0-23) # | |.-day of month (1-31) # |.-month (1-12) OR jan Feb,mar,apr... # |.-day of week (0-6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat# | | # * user-name command to be executed [root@lokott ~] # crontab-e / / Open an interactive window to write commands The command can display no crontab for zhangsan-using an empty onecrontab with the-l parameter below: installing new crontab [root@lokott ~] # crontab-l / / shows the written command code, indicating that 12346* echo "12346" > > 1.txt [root@lokott ~] # cat 1.txt hellohello [root@lokott ~] # cat 1.txt hellohello123461234612346 is written every minute.
Main settings file location:
The global configuration file, located in the file / etc/crontab-- the system default settings are in the directory / etc/cron.*/ user-defined settings (must be dictated) in the file / var/spool/cron/ username. The error information is stored in this file when the wrong command is executed in the process of editing the command: / var/spool/mail/zhangsan [root@lokott ~] # ls / etc/cron.*//etc/cron.d/:0hourly raid-check sysstat/etc/cron.daily/:logrotate man-db.cron mlocate/etc/cron.hourly/:0anacron/etc/cron.monthly/:/etc/cron.weekly/: [root@lokott ~] # su- Zhangsan [zhangsan@lokott ~] $crontab-L5 10 * * 1-5 echo "" > 1.txt / / execute order 6 10 * * 2 from Monday to Friday 10:05 6 echo "ttuu" > > 1.txt / / 10:06 on Tuesdays, Thursdays and Saturdays executes commands 10 10-14 * echo "sdas" > > 1.txt / / every two hours from 10:10 to 14:10 every day * / 5 * * / 2 * * ls. / shell / / every two days Execute the command [root@lokott zhangsan] # cat / var/spool/cron/zhangsan / / user-defined settings every 5 minutes in this file 5 10 * * 1-5 echo "" > 1.txt6 10 * * 2pr 4 6 echo "ttuu" > > 1.txt10 10-14 ls 2 * echo "sdas" > > 1.txt*/5 * * / 2 * * ls. / shell*/1 * echo "sdsad" > > 1.txt [zhangsan@lokott ~] $crontab-e / / I'm going to add a new scheduled task crontab: installing new crontab you have a new email in / var/spool/mail/zhangsan / / prompt me for new content In fact, it is an error message. The information is as follows [zhangsan@lokott ~] $cat / var/spool/mail/zhangsanFrom zhangsan@lokott.localdomain Wed Nov 13 10:05:02 2019Return-Path: X-Original-To: zhangsanDelivered-To: zhangsan@lokott.localdomainReceived: by lokott.localdomain (Postfix, from userid 1001) id 04DC131C6EDF Wed, 13 Nov 2019 10:05:01 + 0800 (CST) From: "(Cron Daemon)" To: zhangsan@lokott.localdomainSubject: Cron ls. / shellContent-Type: text/plain; charset=UTF-8Auto-Submitted: auto-generatedPrecedence: bulkX-Cron-Env: X-Cron-Env: Message-Id: Date: Wed, 13 Nov 2019 10:05:01 + 0800 (CST) VII
This paper mainly introduces and demonstrates the management of processes and scheduled tasks in Linux, including static view (ps) and dynamic view (top) process commands, conditional view (pgrep) and tree structure view (pstree), followed by an introduction to process control, including starting processes, scheduling processes (Ctrl+Z, jobs, fg, bg) and commands for terminating processes (kill, killall, pkill). The last part is the introduction of the scheduled task setting command, that is, the at and crontab commands, in which note that at is valid at one time and needs to be set after the current time (date command to view the current time), while the crontab command is a planned cycle command without year setting.
Finally, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.