Linux process management & task planning



January 19, 2018 Name: Kevin
###

1. Process management

—————————————————————————————————————————————
1. Understand:
Linux is a A multi-user, multi-tasking operating system in which multiple processes can run simultaneously. When the system receives a request, the operating system monitors a queue of tasks waiting to be executed. These tasks include user jobs, operating system tasks, mail, and printing. homework etc. Time slices are allocated to each task according to the priority of each task, each task will be run by the system for a period of time, and then suspended, the system will turn to other tasks until a task is completed, remove
2 from the task queue. Concept: A
process is a separate program running in its own virtual address space. Everything running on Linux can be called a process (job)
. 3. Difference between a process and a program:
a process is not a program that is generated by a program and changes at any time , a program that dynamically uses system resources; a program is a collection of static instructions that does not occupy system resources, and a program can start multiple processes
4. Process type:
interactive process: started and controlled by the shell, can run in the foreground/background ;
Batch process: a series of processes that have nothing to do with the terminal and are completed at a specified time;
daemon process: perform immediate operating system tasks when the system is booted;
5. View system processes:
–ps command:
ps [-aux~] [ -a: display all user processes; -u: print user format, display user name and process start time; -x: display processes without terminal control]
"The meaning of the output field: ~ %CPU: The percentage of CPU time and total time occupied %MEM: The percentage of physical memory used in the total memory VSZ: The size of the virtual memory used by the process/KB; RSS: The total amount of physical memory occupied by the process/KB ; STAT: R: ready to run, S: sleep state, T: stop or trace, I: idle, Z: freeze
–top command Start: + "&" after the command (starts a long formatted text file process, so as not to "crash" the shell at work) – Scheduled start: start at a specified time (automation) 7. End process: – Reason: - the process is using too much CPU time; - has been running for a long time without producing the desired output; - producing too much output to the screen or file; - locking up a terminal or other session process; - due to an operational error , the process is using other wrong input and output files; – Terminate the foreground process: CTRL+C; – Terminate the background process: kill/kill -9 (mandatory is generally not used, if you terminate an update file, the user may lose the updated material or the entire file) 8. Process suspend and resume: – View the shell’s job list: jobs – Suspend: CTRL+Z – Resume: fg (put the suspended command in the foreground for execution); bg (put the suspended command in the foreground) to background execution); ###












2. Task planning (schedule startup process/process automation)

—————————————————————————————————————————————–
1. Concept: in the specified Time to start a job, administrators can use automated tasks to perform regular backups, monitor the system, and run custom scripts, etc. In Linux, cron and at commands are commonly used—cron
:
a.–/etc/crontab file for automation, file details/ Each line:
-minute: minute (any integer between 0-59); -hour: hour (any integer between 0-23); -day: number of days (any integer between 0-31); -month: month ( Any integer between 1-12 / jan feb mar apr may jun jul aug sep oct nov dec); -dayofweek: week (any integer between 0-7 (0/7 means Sunday) / sun mon tue wed thu fri sat ); -username: execute user; -command: execute command/script; [in the above values: "*": represents all valid values; "-": a range of integers; ",": specified interval; "/": Specify the interval frequency (*/3, in the month means /3 months to execute once); the details are as follows:
– 30 21 * * * root /kevin/cleanup.sh
//Every day at 21:30, run the cleanup in the /kevin directory. sh
45 4 1,10,22 * * root /kevin/cleanup.sh
//Run cleanup.sh in the /kevin directory at 4:45 on the 1st, 10th, and 22nd of every month
10 1 * * 6,0 root /kevin /cleanup.sh
//Run cleanup in the /kevin directory at 1:10 every Saturday and Sunday, sh
0,30 18-23 * * * root /kevin/cleanup.sh
//Every day between 18:00-23:00 Run cleanup.sh in the /kevin directory for 30 minutes
0 23 * * 6 root /kevin/cleanup.sh
//Run cleanup,sh in the /kevin directory at 23:00 every Saturday
] 『–Linux uses the run-parts script to execute /etc/cron.hourly(/hourly execution) etc/cron.daily(/daily execution) etc/cron.weekly(/weekly execution) etc/cron.monthly(/monthly execution); – if desired To be executed according to the schedule instead of /hour/day/month, it can be added to the /etc/cron.d directory (this directory uses the same syntax as /etc/crontab); 』 b.
–crontab command to automate :
-Command: crontab [-u [username]] (not required for non-root users) [-ler][-l: list the contents of the crontab; -e: edit the crontab file; -r: delete the crontab file] "to cron Before a process submits a crontab file, you need to set the environment variable EDITOR – edit the .bash_profile file in the user’s home directory and add: EDITOR=vi;export EDITOR After creation, a copy will be created /var/spool/cron/

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325955389&siteId=291194637