Process concept
task struct: The data structure in which the kernel stores process information
task list: a linked list of task structs of multiple tasks
Create process CoW Copy on Write
The child process will copy the memory space of the parent process to the child process only when the data changes, otherwise the parent process and the child process will occupy the same memory space.
Several states of the process
1. Create
2. Ready
3. Execute
4. Blocking
5. Termination
Process priority
The lower the number, the higher the priority
Each priority contains two queues, namely the running queue and the expired queue. In the process of the CPU running the same priority, the running queue and the expired queue will switch continuously.
process memory
The memory storage process information is based on the page frame as the basic unit, and the size of each page is 4k
LRU memory least recently used algorithm
Physical address space and virtual address space (linear address space)
For an application, the operating system will allocate a real memory space to the process, but the application will virtualize this physical space into the entire memory space in the operating system.
communication between processes
same host
signal signal
shared memory shared memory
semaphore, a kind of counter
different hosts
socket IP address + port number
RPC remote call
MQ message queue
Process management tool
kill
killall
pkill
Process front and back switch
18, 19 represent the signal type
Although cmd & can send commands to the background for execution, it is still connected to the executing terminal. When the terminal is closed, the background process will also be terminated.
Stripping the relationship between background processes and terminals
nohup COMMAND &>/dev/null &
screen;COMMAND
If the background process started with nohup closes the corresponding terminal, the parent process of the background process changes from the original Bash process to systemd (the first process of the system)
Parallel execution of processes
Run multiple processes at the same time to improve efficiency
method 1
vi all.sh
f1.sh&
f2.sh&
f3.sh&
Method 2
(f1.sh&);(f2.sh&);(f3.sh&)
Method 3
{ f1.sh& f2.sh& f3.sh& }
Scheduled Tasks
Execute a one-time task at some point in the future
batch: The system chooses its own free time to perform the specified task (it is used less frequently)
at: specify a specific point in time to execute certain commands
Command files are saved in the /var/spool/at directory
The standard output in the scheduled task command will be sent to the user as an email by default, and the standard output can be redirected to &> /dev/null
Setting rules for blacklist and whitelist
There is a blacklist /etc/at.deny file in the system by default, and the whitelist file needs to be manually added /etc/at.allow
If there is a whitelist file, only users in the whitelist will be viewed. Only users in the whitelist have permission to create at tasks. Other users have no right to create at tasks regardless of whether they are in the blacklist or not.
If only the blacklist file is available, only users in the blacklist will be viewed, and only the blacklisted users will not have the right to create tasks, and other users can create scheduled tasks.
If neither the blacklist file nor the whitelist file exists, only the root user can create tasks, and other users cannot create scheduled tasks.
Run a task periodically
cron
/etc/crontab configuration format Only the root user has permission to modify this file
minute (0-59) hour (0-23) day (1-31) month (1-12) week (1-7) username cmd
The black and white list settings are the same as the at rule
Ordinary users create scheduled tasks
crontab -e
The stored task files are stored in the /var/spool/cron directory