When we work in 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 processes that intensively access the disk, we prefer that they run during non-peak hours of the day (such as early morning). To enable these processes to run in the background, that is, not on the terminal screen, several options are available. & When a job is running in the foreground, the terminal is occupied by the job; you can add & after the command to run it in the background. For example: sh test.sh & command > out.file 2>&1 & In this way, all standard output and error output will be redirected to a file called out.file. PS: After you successfully submit the process, a process ID will be displayed, which can be used to monitor the process or kill it. (ps -ef | grep process number or kill -9 process number) nohup After using the & command, the job is submitted to the background for execution. The current console is not occupied, but once the current console is closed (when logging out of the account), the job will stop running. The nohup command can continue running the corresponding process after you log out of your account. nohup means no hang up. The general form of the command is: nohup command & If you submit a job using the nohup command, then by default all output from the job is redirected to a file named nohup.out, unless an output file is specified otherwise: nohup command > myout.file 2>&1 & After using nohup, many people just ignore it. In fact, it is possible that the command will end automatically when the current account is exited or ended abnormally. Therefore, after using the nohup command to run the command in the background, you need to use exit to exit the current account normally to ensure that the command continues to run in the background. ctrl + z Ctrl+c jobs The jobs -l option displays the PID of all tasks. The status of jobs can be running, stopped, or Terminated. But if the task is terminated (killed), the shell removes the task's process ID from the list known to the current shell environment. 2>&1Analysis command >out.file 2>&1 &
The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Information transmission and function calls between WeChat mini program pages and components
>>: WeChat applet implements the snake game
Yesterday when I was implementing the function of...
Please handle basic operations such as connecting...
How to shorten the page rendering time on the bro...
Copy code The code is as follows: <!DOCTYPE ht...
This article example shares the specific code of ...
Summarize 1. Similarities Both can change the int...
1. After connecting and logging in to MySQL, firs...
The first step is to download the free installati...
Table of contents 1 Introduction 2 Trigger Introd...
Table of contents What is a headless browser? Why...
Table of contents 1. Introduction to FastDFS 1. I...
General mobile phone style: @media all and (orien...
1. Modify MySQL login settings: # vim /etc/my.cnf...
Preface Tomcat is a widely used Java web containe...
Table of contents Overview 1. Clearly understand ...