English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Linux nohup Befehl

Linux Command大全

nohup Englische Bezeichnung no hang up (nicht abschalten), verwendet, um Befehle im Hintergrund ohne Abbruch zu starten, der Abgang des Terminals beeinflusst nicht den Lauf der Anwendung.

nohup Befehl, standardmäßig (bei nicht umgeleiteten Ausgaben) gibt eine Datei namens nohup.out im aktuellen Verzeichnis aus, wenn die nohup.out-Datei im aktuellen Verzeichnis nicht schreibbar ist, wird die Ausgabe umgeleitet nach $HOME/nohup.out Datei.

Berechtigungen

Alle Benutzer

Syntaxformat

 nohup Command [Arg …] [ & ]

Parameter Description:

Command: Auszuführender Befehl.

Arg: Einige Parameter, um die Ausgabedatei zu spezifizieren.

&: Befehle im Hintergrund ausführen, der Terminal-Abgang beeinflusst den Befehl nicht.

Online-Beispiel

Die folgenden Befehle werden im Hintergrund ausgeführt, im Verzeichnis root3codebox.sh Skript:

nohup /root/w3codebox.sh &

Wenn Sie auf dem Terminal die folgenden Ausgaben sehen, bedeutet dies, dass der Lauf erfolgreich war:

appending output to nohup.out

At this time, we open the root directory and can see that the nohup.out file has been generated.

If you want to stop it, you need to use the following command to find the PID of the script running nohup and then use the kill command to delete it:

ps -aux | grep "w3codebox.sh" 

Parameter Description:

  • a : Display all programs
  • u : Display in the format of the user
  • x : Display all programs, without distinguishing terminals

You can also use ps -def | grep "w3You can find it using the "codebox.sh" command.

After finding the PID, you can use kill PID to delete it.

kill -9  Process ID PID

The following command runs the w in the root directory in the background3Run the codebox.sh script and redirect input to w3codebox.log file:

nohup /root/w3codebox.sh > w3codebox.log 2>&1 &

2>&1 Explanation:

Standard error is 2 Redirected to standard output &1 , standard output &1 Then it is redirected as input to w3in the codebox.log file.

  • 0 – stdin (standard input, standard input)
  • 1 – stdout (standard output, standard output)
  • 2 – stderr (standard error, standard error output)

Linux Command大全