In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you what the Linux background execution commands are, I believe that most people do not know much about it, so share this article for your reference, I hope you will learn a lot after reading this article, let's go to know it!
Linux job
A Job is a process managed by shell (each job has an associated PID), and each job is assigned a linear job ID.
There are two forms of homework:
Foreground: when you enter a command in the terminal window, this command will occupy the terminal window until the command is executed. This is a foreground JobBackground: when you add a & symbol to the command, the command will not occupy the terminal window (you can continue typing in shell prompt). This is a background JobLinux job control command.
Using job control commands, you can run and manage multiple jobs in Shell. But you can only use the job control command in the Shell that starts the job.
Command description jobs lists all Job, followed by parameters to filter bg% n to put the current / specified Job in the background to run fg% n to bring the current / specified Job to the foreground to run
There are also some quick actions related to the job:
&: let the command or script run Ctrl+Z in the background: interrupt the foreground job and place it in the background Ctrl+C: terminate the current foreground job nohup: run the job in the background even if the terminal is closed (usually with the & above)
Add & at the end of the original command to make the job run in the background. The following example: execute the sleep command in the background
$sleep 100 &
[1] 14488
Shell returns the result: job ID in square brackets, followed by PID;. Use the jobs command to check the status: the background job is completed after 100s.
[root@recv-data recv] # jobs
[1] + Running sleep
....
[root@recv-data recv] # jobs
[1] + Done sleep
Manage the job
For foreground work
Execute Ctrl+Z to abort the foreground job and place it in the background; then you can use the bg% n command to make the aborted background job run.
# abort the foreground job and put it in the background
$sleep 100
^ Z
[1] + Stopped sleep
$jobs
[1] + Stopped sleep
# bg command makes jobs aborted in the background run
$bg 1
[1] + sleep
For jobs in the background, fg% n switches back to the foreground to execute.
# the following shows a running background job
$jobs
[1] + Running sleep
# switch back to the foreground
$fg 1
Sleep 100
"
As we all know, Ctrl+C terminates the current foreground job, not to mention.
Nohup: also execute when the terminal is closed.
In many cases, you log in to the remote server through ssh, and then execute the Shell script or command, and if you exit the terminal (terminate the remote connection), the process / command will be killed. If you are not sure when the job will be completed, it is best to let the job run in the background, but if you exit the system, the job will be stopped and terminated by Shell. How to make the job run in the background when the process receives the SIGHUP?
At this point, we need to use the nohup command so that our long-running Shell scripts or commands can still be executed when we log out of the system (usually in the background).
"
As the name implies: nohup is a POSIX command that ignores the HUP (hang up) signal.
The above is all the contents of the article "what is the command to execute the job in the background in Linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.