ArticleDirectory
- Cron and crontab
- At command
- & Commands
- Nohup command
When we work on a terminal or console, we may not want to occupy the screen by running a job, because there may be more important things to do, such as reading emails. For intensive disk access processes, you may want them to run during off-peak hours every day. To enable these processes to run in the background, that is, they do not run on the terminal screen, there are several options available:
- Set the crontab file and use it to submit a job.
- Use the AT command to submit a job.
- Submit a job in the background.
- Use the nohup command to submit a job.
Cron: System scheduling process. It can be used to run jobs during off-peak hours every day, or during different periods of one week or one month.
At command: it is used to run some special jobs at a specific time, or in a later non-peak hours or peak hours.
&: It is used to run a process that takes a short time in the background.
Nohup: use it to run a command in the background, even if the user exits, it will not be affected.
Cron and crontab
Cron is the main scheduling process of the system. It can run jobs without human intervention. A command called crontab allows you to submit, edit, or delete a job. Each user can have a crontab file to save scheduling information. You can use it to run any shell script or command once an hour or Wednesday, depending on you. Every user can have their own crontab files, but in a large system, the system administrator usually disallow these files, but only keeps one such file in the entire system.
The system administrator disables or allows users to own crontab files through cron. deny and cron. allow.
For more information about Cron, see crontab and cron.
At command
The at command allows you to submit a job to the cron daemon to run the job later. The later time may be 10 minutes later or several days later. If you want to run it after one month or longer, you 'd better use the crontab file.
Once a job is submitted, the AT command retains all the current environment variables, including the path. Unlike crontab, it only provides the default environment. All outputs of the job will be sent to the user by email. Unless you have redirected the output, most of the time it is redirected to a file.
Like crontab, the root user can use the at. allow and at. deny files in the/etc directory to control which users can use the AT command and which users cannot. However, the use of AT commands is not as strict as that of crontab.
& Commands
When running a job on the foreground, the terminal is occupied by the job, but it does not occupy the terminal when running the job on the background. You can run the job in the background using the & command.
The command is generally in the following format:
Command &
Why do I need to execute commands in the background? Because when executing commands in the background, you can continue to use your terminal to do other things. Suitable for running commands in the background, such as find, time-consuming printing jobs, time-consuming sorting, and shell scripts. Be careful when running jobs in the background: do not execute commands that require user interaction in the background, because your machine will be silly there. However, running a job in the background will output the result to the screen, interfering with your work. If a job running in the background produces a large amount of output, you 'd better use the following method to redirect its output to a file:
Command> out.File 2> &1&
In the preceding example, all standard output and error output are redirected to an out. File file.
After a process is successfully submitted, a process number is displayed, which can be used to monitor or kill the process.
Nohup command
If you are running a process and you think the process will not end when you exit the account, you can use the nohup command. This command can continue running the corresponding process after you exit the account. Nohup means no hang up ).
The command is generally in the following format:
Nohup command &
If you use the nohup command to submit a job, all the output of the job is redirected to a file named nohup. Out by default, unless the output file is specified separately:
Nohup command> myout.File 2> &1
In the preceding example, the output is redirected to the myout. File file.