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 > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge of "how Linux switches tasks in the foreground and background". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "how to switch tasks to the foreground and background in Linux" can help you solve the problem.
Linux is a multitasking operating system that can run multiple tasks at the same time.
When we run a process using Node or Flask, the process takes up the terminal.
For example:
# python cutword.py * Serving Flask app 'cutword' (lazy loading) * Environment: production WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. * Debug mode: off * Running on all addresses. WARNING: This is a development server. Do not use it in a production deployment. * Running on http://10.150.39.18:7776/ (Press CTRL+C to quit) runs the process in the background
We can add the & symbol after the command to switch the process to the background.
For example:
# nohup python cutword.py > / dev/null 2 > & 1 & [1] 30979
The purpose of nohup is to run commands without hanging up.
Whether or not the output of the nohup command is redirected to the terminal, the output is appended to the nohup.out file in the current directory.
Nohup is required if the program is always executed in the background, even if the current terminal is closed (& cannot be done). This command can continue to run the corresponding process after you exit your account / close the terminal.
> / dev/null 2 > & 1 ignores both standard output and error output.
The last-the process will run in the background.
[1] 30979 indicates the background task number and process ID, respectively.
View background tasks
We can use the jobs command to view the list of processes running in the background.
# jobs [1] + running nohup python cutword.py > / dev/null 2 > & 1 &
When the terminal is closed, jobs cannot see the background task list on another terminal, so use ps (process View Command).
# ps-aux | grep "cutword.py" switches the process to the foreground
We can use the fg% background number to switch the specified process back to the foreground.
# fg% 1nohup python cutword.py > / dev/null 2 > & 1
We will find that the program will be stuck in the terminal all the time. At this point, we can use ctrl+z to cut it to the background again.
# fg% 1nohup python cutword.py > / dev/null 2 > & 1 ^ Z [1] + stopped nohup python cutword.py > / dev/null 2 > & 1
However, we will find that the process has become the state of stopped, and we can also see its status in the list of background processes.
This is also a feature of the ctrl+z command: switch the process to the background and stop running.
If we want to get it running again, we can use the bg command.
# bg 1 [1] + nohup python cutword.py > / dev/null 2 > & 1 & terminate background tasks
If we want to kill a background process, we can use the kill command.
The kill command can be used in two ways:
Kill pidkill% N
For example, if we want to kill the process numbered 1 in the background, we can do this:
# kill% terminated jobs [1] + terminated nohup python cutword.py > / dev/null 2 > & 1 that's all for "how Linux switches tasks in the foreground and background". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
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.