linux后台执行命令英文
-
The command for executing a command in the Linux background is “nohup”.
Nohup stands for “no hang up” and ensures that the specified command continues to run even after the user logs out or the terminal session ends. This allows the command to run in the background without being interrupted.
The syntax for executing a command in the background using nohup is as follows:
nohup [command] &
For example, if you want to execute the command “python script.py” in the background, you would use the following command:
nohup python script.py &
Once the command is executed with nohup and the “&” symbol, it will keep running even if you close the terminal session or log out. Any output generated by the command will be redirected to a file named “nohup.out” by default.
To view the output of the command, you can use the “tail” command as follows:
tail -f nohup.out
This will allow you to monitor the ongoing output of the command in real-time.
In addition to nohup, you can also use the “screen” command in Linux for running a command in the background. The “screen” command creates a virtual terminal that continues to run even after you log out. This is useful for long-running processes or tasks that require ongoing monitoring.
To start a screen session, you can use the following command:
screen
Inside the screen session, you can execute your command as usual. To detach from the screen session without ending the command, you can press “Ctrl+a” followed by “d”.
To reattach to a detached screen session, you can use the command “screen -r”.
Both nohup and screen are commonly used methods for running commands in the background in Linux and ensuring they continue to run even after your session ends. Depending on your specific requirements, you can choose the method that best suits your needs.
2年前 -
在Linux中,后台执行命令可以使用以下几种方式:
1. 使用&符号:在命令末尾输入&符号,表示将命令放入后台执行。例如:
“`
$ command &
“`2. 使用nohup命令:nohup命令用于运行一个命令,不受终端断开的影响。可以将命令放入后台执行,并将输出重定向到指定文件。例如:
“`
$ nohup command > output.txt &
“`3. 使用Ctrl+z和bg命令:Ctrl+z快捷键可以将当前正在运行的命令暂停,并返回到终端。然后可以使用bg命令将命令放入后台执行。例如:
“`
$ command
[Ctrl+z]
$ bg
“`4. 使用screen命令:screen命令可以创建一个多重终端窗口,并在窗口之间切换。可以在screen窗口中运行命令,并将窗口放入后台执行。例如:
“`
$ screen
$ command
[Ctrl+a d](将screen窗口放入后台)
“`5. 使用tmux命令:tmux是一个终端复用器,类似于screen命令。可以使用tmux创建一个会话,并在会话中运行命令。命令运行后,可以将会话放入后台执行。例如:
“`
$ tmux new-session -s mysession
$ command
[Ctrl+b d](将tmux会话放入后台)
“`以上是在Linux中后台执行命令的几种常见方式。通过这些方法,可以让命令在后台运行,而不会阻塞终端的使用。
2年前 -
The correct term for running a command in the background in Linux is called “running a command in the background”. This allows a command to run independently of the current shell session, freeing up the terminal for other tasks.
To run a command in the background, you can use one of the following methods:
1. Using ‘&’ symbol:
For example, to run the command “sleep 10” in the background, you would enter:
“`
sleep 10 &
“`2. Using ‘nohup’ command:
The ‘nohup’ command allows you to run a command that continues to run even after the terminal session ends.
For example, to run the command “sleep 10” in the background using ‘nohup’, you would enter:
“`
nohup sleep 10 &
“`
This will create a file named “nohup.out” in the current directory, which will contain any output generated by the command.3. Using ‘disown’ command:
The ‘disown’ command can be used to detach a process from the current shell session.
First, run the command in the foreground and then press ‘Ctrl + Z’ to pause the process.
Then, use the ‘bg’ command to resume the process in the background:
“`
sleep 10
“`
Press ‘Ctrl + Z’
“`
bg
“`
Finally, use the ‘disown’ command to detach the process from the shell session:
“`
disown
“`These methods allow you to run commands in the background on Linux, freeing up your terminal for other tasks while the command continues to run. Make sure to check the output and any necessary logs to ensure the command is running as expected.
2年前