Killall command
- Killall [Option] [Signal] process name
- Option-I interactive, ask if you want to kill a process-I ignore the case sensitivity of the process name
// Killall-9 httpd
Pkill command
- Pkill [Option] [Signal] process number
- Option-t terminal number: Kick out the user according to the terminal number
Note: The pkill and killall commands are basically the same.
// View the current logon user $ w 19:53:45 up, 1 USER, load average: 0.00, 0.01, 0.05 user tty from login @ idle jcpu pcpu WHATroot tty1-3: 02 m 23.87 s 0.23 s-bashroot pts/0 192.168.44.1 04:47 0.00 s 0.22 s 0.00 s wroot pts/0 192.168.44.1 04:47 0.00 s 0.22 s 0.00 s-bash // only root users can kill local user # pkill-9-t tty1
Introduction to modifying process priorities of process prioritiesLinux is a multi-user, multi-task operating system, and many processes are notified to run in Linux. However, the CPU can only calculate one command within a unified clock cycle. The process priority determines the processing sequence of each process.
$ Ps-leF s uid pid ppid c pri ni addr sz wchan tty time limit 4 S 0 1 0 0 80 0-29895 -? At 00:00:02 systemd1 S 0 2 0 0 80 0-0 -? 00:00:00 kthreadd1 S 0 3 2 0 80 0-0 -? 00:00:00 ksoftirqd/01 S 0 5 2 0 60-20-0 -? 00:00:00 kworker/0: 0H1 S 0 7 2 0 80 0-0 -? 00:00:03 rcu_sched1 S 0 8 2 0 80 0-0 -? 00:00:00 rcu_bh1 S 0 9 2 0-40--0 -? 00:00:00 migration/05 S 0 10 2 0-40--0 -? At 00:00:00 watchdog/05 S 0 11 2 0 80 0-0 -? 00:00:00 kdevtmpfs1 S 0 12 2 0 60-20-0 -? 00:00:00 netns // PRI stands for Priority, and NI stands for Nice. Both values are priorities. The smaller the number, the higher the priority of the process.
Several Notes for changing the NI value
- The value range of NI is-20 to 19.
- The average user can adjust the NI value range from 0 to 19, and can only adjust their own processes
- Normal users can only increase the NI value rather than decrease it. For example, if the original NI value is 0, it can only be adjusted to a value greater than 0.
- The root user can set the process NI value to a negative value, and can adjust any user's Process
- PRI (final value) = PRI (original value) + NI
- The user can only modify the NI value, but cannot directly modify the PRI
Nice command
- Nice [Option] the nice command can directly assign the NI value to the newly executed command, but it cannot modify the NI value of an existing process.
- Option-n NI value to assign NI value to the command
// The NI value of a process can be modified only when it is started. It cannot be modified when the process is running # nice-n-5 service httpd start
Renice command
- Renice [Priority] PID renice command is to modify the NI value of an existing process
// Use renice to modify the NI value of an existing process # renice-10 2125
Work Management OverviewJob Management refers to managing multiple jobs at the same time on a single logon terminal (that is, the shell Interface for Logon.
Notes
The current login terminal can only manage the work of the current terminal, but cannot manage the work of other login Terminals
Commands placed in the background must be able to run for a period of time so that we can capture and operate on this job.
Commands executed in the background cannot interact with the foreground or need to be input in the foreground. Otherwise, the commands executed in the background can only be paused, but cannot be run.
Work Management Method process put into the background
- Use & put commands in the background
- Use the ctrl + z shortcut to save the command to the background
// Put the command in the background and execute $ tar-zcf etc.tar.gz/etc & // press the ctl + z shortcut key in the background to suspend $ topctl + z in the background
View background work
- Jobs
- Option-l display the PID of the job. Note: "+" indicates the last job to be placed in the background. It is also the work that is replied by default when the job is replied ." -"Number" indicates the work of putting the last and second digits into the background.
$ Top & $ top // ctrl + z put in the background // view the background processes. Both top processes are stopped because top displays the processes to the foreground users and interacts with the foreground, you cannot run $ jobs [1]-Stopped top [2] + Stopped top $ vi abc & $ jobs [1] Stopped top [2]-Stopped top [3] + Stopped in the background vi abc
Resume paused background work to the foreground for execution
- Fg % work number
- Parameter % work Number % can be omitted, but pay attention to the difference between work and PID
Resume paused tasks in the background to be executed in the background.
- Bg % work number
- Parameter % work Number % can be omitted, but pay attention to the difference between work and PID
Note: commands executed in the background cannot interact with the foreground, otherwise they cannot be executed in the background.
Introduction to running background commands out of the logon TerminalPut the command in the background and can only be executed on the current logon terminal. Once you exit or close the terminal, the background program stops.
How to run background commands without logging on to the terminal
- Add the command to be executed in the background to the/etc/rc. local file.
- The system scheduled task allows the system to execute a background command at a specified time.
- We recommend that you use the nohub command.
- Daemon, such as mysqld.
// Execute the rc. local file $ cat/etc/rc. localtouch/var/lock/subsys/local // when the system starts. Note: The file is not created here and the timestamp of the file is changed.
// Execute for. sh # vi for. sh # in Terminal 1 #! /Bin/bashfor (I = 0; I <= 1000; I = I + 1) do echo 11>/root/. log sleep 10 done # nohup/root/. sh & // close Terminal 1 // open Terminal 2, ps aux can see. sh is still running
System resource view vmstat command to monitor system resourcesVmstat [Refresh Interval refresh times]
$ vmstat 1 3procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu----- r b swpd free buff cache si so bi bo in cs us sy id wa st 0 0 70280 133280 13140 303244 0 4 60 16 53 121 1 1 98 0 0 0 0 70280 133264 13140 303248 0 0 0 0 40 201 1 0 99 0 0 0 0 70280 133264 13140 303248 0 0 0 0 43 183 1 0 99 0 0
- Process Information Field-r: Number of processes waiting for running. The larger the number, the more busy the system is.-The number of processes that cannot be awakened by B. The larger the number, the more busy the system is.
- Memory Information Field-usage of swpd virtual memory, unit KB-free idle memory capacity, unit KB-buff buffer memory capacity, unit KB-cache buffer memory capacity, unit: KB
- The information field of the swap partition-si refers to the number of data transferred from the disk to the memory. Unit: KB-so refers to the amount of data exchanged from the disk to the disk. Unit: KB. The larger the two numbers, it indicates that the data needs to be frequently exchanged between the disk and memory, and the worse the system performance.
- Io disk read/write information field-the total amount of data that bi reads from Block devices. The unit is the total amount of data that block-bo writes to block devices. The unit is block. The larger the number of times, the more busy the system I/O.
- System Information Field-in: Number of interrupted processes per second-number of time switches performed by cs per second. The larger the two numbers, the communication between the system and the interface device is very busy.
- CPU Information Field-us percentage of CPU computing time consumed by non-kernel processes-sy percentage of CPU computing time consumed by kernel processes-id percentage of idle CPU-wa consumption during I/O CPU usage-Percentage of CPU occupied by the st Virtual Machine
Dmesg kernel detection information during startup$ dmesg |grep CPU
Free command to view memory usage status
- Free [-B |-k |-m |-g]
- Option-B is displayed in bytes.-k is displayed in KB. The default value is KB.-m is displayed in MB.-g is displayed in GB.
/* Total memory used free idle memory shared by multiple processes buffers buffer memory cached cache memory default unit is KB */$ free -m total used free shared buff/cache availableMem: 983 545 124 6 313 273 Swap: 1906 68 1838
View CPU Information$ cat /proc/cpuinfo
Uptime commandDisplay the system startup time and average load, that is, the first line of the top command. The w command can also see this data.
$ Uptime 10:10:47 up 10:11:35, 1 user, load average: 0.18, 0.10, 0.09 $ w up, 1 user, load average: 0.09, 0.09, 0.09 user tty from login @ idle jcpu pcpu WHATroot tty7: 0 a 16 17: 20 m 49.38 s 0.28 s/sbin/upstart -- user
View System and kernel information
- Uname [Option]
- Option-a view all system information-r view kernel version-s view kernel name
Determine the number of digits of the current system
View the release version of the current Linux System
Lists information about files opened or used by a process.
- Lsof [Option] lists information about a process calling or opening a file.
- Option-c string only lists files opened by processes starting with a string-u user name only lists files opened by a user's processes-p pid list files opened by a PID Process
// Query the files called by all processes in the query system $ lsof | more // query which process calls a file $ lsof/sbin/init // check which files are called by the httpd process $ lsof- c httpd // follow the user name, query the files called by a user process $ lsof-u root
The difference between cache and buffer is simply that cache is used to accelerate data "read" from the hard disk, while buffer is used to accelerate data "write" to the hard disk.
System scheduled task
- At one-time scheduled task
- Crontab cyclic scheduled task
- Crontab settings of the system
- Anacron Configuration
At command to confirm at Installation// Whether the at service is installed # chkconfig -- list | grep atd # service atd status
At Access Control
If/etc/. allow file, only write/etc/. users in the allow file (whitelist) can use the at command (/etc/. deny files are ignored)
If there is no/etc/at. allow file in the system and only the/etc/at. deny file is available, users in the/etc/at. deny file (blacklist) cannot use the at command.Does not work for root
If the two files do not exist in the system, only the root user can use the at command.
At commandAt [Option] Time option-m when at is finished, whether or not the command has output, the user-c work number that uses e-mail notification to execute the at command shows the actual content of the at work time:-HH: MM for example: 02: 30-HH: MM YYYY-MM-DD For example: 02: 30 2013-07-25-HH: MM [am | pm] [month] [date] example: 02: 30 July 25-HH: MM [am | pm] + [minutes | hours | days | weeks] example: now + 5 minutes
Example$ At now + 2 minutesat>/root/hello. sh>/root/hello. logat> <EOT> // restart at $ at 2013-07-26at>/bin/syncat>/sbin/shutdown-r now
Other at management commands
Atq
- Query at tasks on the current server
Atrm [Work number]
- Deletes a specified at task.
Crontabcrond service management and access control// Check whether the crond service is installed and started # service crond restart # chkconfig crond on
Access Control
When there is a/etc/cron. allow file in the system, only users who write this file can use the crontab command. users who do not write this file cannot use the crontab command. Similarly, if this file exists, the/etc/cron. deny file will be ignored. The/etc/cron. allow file has a higher priority.
When the system only contains the/etc/cron. deny file, the user who writes the file cannot use the crontab command. If the file is not written, the crontab command can be used.
User crontab settings
- Crontab [Option]
- Option:-e: Edit crontab scheduled task-l query crontab task-r: delete all crontab tasks of the current user
// Edit the crontab command $ crontab-e ***** command
ProjectDescriptionRangeNumber of minutes in the first * hour * number of minutes in the second * number of hours in the day * Number of days in the month * number of months in the year * number of months 1-12 in the year the number of weeks in a week is 0-7 (both 0 and 7 represent Sunday)Special symbolsDescription* Represents any time. For example, the first "*" indicates that the execution is performed once every minute in an hour, indicating the discontinuous time. For example, the "0, 12, 16 *** command" indicates that the command is executed at 08:00, and every day-representing the continuous time range, for example, the "0 5 ** 1-6 command" means to execute the command at 05:00 from Monday to Saturday */n, which indicates how often the command is executed. For example, the "*/10 *** command" indicates that the command is executed every 10 minutes.// Cron command, which is executed at 00:00 on the 1st and 15th of every month. // note: the day of the week and the number of the week are not recommended to appear at the same time. They define the day as the day. Very confused. 0 0 111*1 command // example // write 111 */5 *** echo>/root/test every 5 minutes
Crontab considerations
The six options cannot be blank and must be filled in. If "*" is not specified, it indicates any time.
Crontab scheduled task. The minimum effective time is minute and the maximum time range is month. If you want to execute it at a time on January 1, 2018, it cannot be identified at 03:30:30.
When defining the time, it is recommended that the date and week do not appear in a scheduled task, because they are all in the unit of day, the shovel is easier to make administrators confused.
In a scheduled task, whether it is to write commands directly or in a script,It is best to use absolute paths.
Note: The environment variables of the scheduled task are not necessarily the same as those saved in $ PATH. Therefore, use the absolute PATH in crontab.
Crontab settings set by the System"Crontab-e" is the command executed by each user. That is to say, different user identities can execute their own scheduled tasks. However, some scheduled tasks need to be executed by the system. We need to edit the configuration file/etc/crontab.
// Here, crontab is a scheduled task of a common user $ crontab-e // configuration file $ vim/etc/crontabSHELL =/bin/bashPATH =/sbin in the system scheduled task // CentOS 5: /bin:/usr/sbin:/usr/binMAILTO = rootHOME =/# run-parts01 *** root run-parts/etc/cron. hourly02 4 *** root run-parts/etc/cron. daily22 4 ** 0 root run-parts/etc/cron. weekly42 4 1 ** root run-parts/etc/cron. monthly
// View the directories and files related to crontab in/etc # ls/etc/croncron. d/cron. hourly/crontab cron. daily/cron. monthly/cron. weekly/
How to execute scheduled tasks of the system
Anacron ConfigurationAnacron is a scheduled task that is missed during system shutdown. It can be executed after the system is started.
Anacron detection cycle
Anacron uses one day, seven days, and one month as the detection cycle
The cron. {daily, weekly, monthly} file exists in the/var/spool/anacron/directory of the system to record the time when cron was last executed.
Compared with the current time, if the difference between the two times exceeds the specified time difference of anacron, it proves that cron tasks are not executed.
Differences between CentOS 6.x
In the old CentOS version, the/etc/cron. {daily, weekly, monthly} directories will be called by cron and anacron, which is easy to execute repeatedly.
In CentOS 6. x, it will only be called by anacron, avoiding repeated execution.
In CentOS 6. x, anacron is no longer a service, but a system command.
Anacron configuration file$ Vi/etc/anacrontab #/etc/anacrontab: configuration file for anacron # See anacron (8) and anacrontab (5) for details. SHELL =/bin/shPATH =/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin: /usr/binHOME =/rootLOGNAME = rootRANDOM_DELAY = 45START_HOURS_RANGE = 3-22 # These replace cron's entries1 5 cron. daily run-parts -- report/etc/cron. daily7 10 cron. weekly run-parts -- report/etc/cron. weekly @ monthly 15 cron. monthly run-parts -- report/etc/cron. monthly # Number of days force delay (minutes) the actual execution of the work name command
Cron. daily job to explain the execution process
First, read/var/spool/anacron/cron. daily the last time anacron was executed.
Compared with the current time, if the difference between the two times exceeds one day, cron. daily will be executed.
The task can only be executed -.
The forced delay time is 5 minutes, and then the random delay is 0-45 minutes.
Use the nice command to specify the default priority and run the run-parts script to execute all executable files in the/etc/cron. daily directory.