Tutorials  /  Linux Basics

Nohup Command in Linux

Ccentron Redaktion · March 2024 ·6 min read ·Linux Basics, Tutorial

When exiting the shell of a Linux System, all running processes are usually terminated or hang up. So what do you do If you still want to keep the processes running even exiting the shell/terminal? This is where the nohup command comes in.

Nohup Command

Nohup, short for no hang up is a command in Linux systems that keep processes running even after exiting the shell or terminal. Nohup prevents the processes or jobs from receiving the SIGHUP (Signal Hang UP) signal. This is a signal that is sent to a process upon closing or exiting the terminal. In this guide, we take a look at the nohup command and demonstrate how it can be used.

VM

Matching infrastructure at centron

No hardware needed to follow along: ccloud³ VMs with full root access start at €3.12 per month, billed by the hour and ready in seconds. Rent a cloud server →

Nohup Command Syntax

Nohup command syntax is as follows;

Code
nohup command arguments

OR

Code
nohup options

Let’s see how the command comes into play

Checking the version of Nohup

You can begin by checking the version of Nohup using the syntax below

Code
nohup --version

Output

Nohup version

Starting a process using Nohup

If you want to keep your processes/jobs running, precede the command with nohup as shown below. The jobs will still continue running in the shell and will not get killed upon exiting the shell or terminal.

Code
nohup ./hello.sh

Output

Nohup script

From the output above, the output of the command has been saved to nohup.out to verify this run,

Code
cat nohup.out

Output

Cat nohup out

Additionally, you can opt to redirect the output to a different file as shown

Code
nohup ./hello.sh > output.txt

Once again, to view the file run

Code
cat output.txt

Output

Redirect nohup output to a txt file

To redirect to a file and to standard error and output use the > filename 2>&1 attribute as shown

Code
nohup ./hello.sh > myoutput.txt 2>&1

Output

Redirect standard out and standard error

Starting a process in the background using Nohup

To start a process in the background use the & symbol at the end of the command. In this example, we are pinging google.com and sending it to the background.

Code
nohup ping google.com &

Output

Nohup run process in the background

To check the process when resuming the shell use the pgrep command as shown

Code
pgrep -a ping

Output

Pgrep ping google

If you want to stop or kill the running process, use the kill command followed by the process ID as shown

Code
kill 2565

Output

Kill nohup PID

Summary

  • All processes that are run using the nohup command will ignore the SIGHUP signal even upon exiting the shell.
  • Once a job is started or executed using the nohup command, stdin will not be available to the user.
  • By default, the nohup.out is used as the default file for stdout and stderr.
Jetzt 200 € Guthaben sichern

Testen Sie Ihr Setup auf ccloud³

Registrieren Sie sich in der ccloud³ und erhalten Sie 200 € Startguthaben für Ihr Projekt – z. B. für eine PostgreSQL-VM mit automatischen Backups.

centron Redaktion Technische Redaktion

Das Redaktionsteam von centron schreibt Anleitungen aus dem Betriebsalltag: getestet auf unserer eigenen Plattform, betrieben im Rechenzentrum in Hallstadt bei Bamberg.

Kategorie Linux Basics
Teilen
Noch offene Fragen?

Our team will help you with your specific setup - in German or English, by people who run the platform themselves.

War dieses Tutorial hilfreich?

Your answer is stored anonymously and helps us improve our tutorials.

Kommentare

No comments yet - be the first to ask a question about this tutorial.

Sign in to comment

Comments are open to centron customers. Sign in to your account to ask a question about this tutorial.

Weiterlesen

Das könnte Sie auch interessieren

Jetzt kostenlos anfangen

Melden Sie sich an und erhalten Sie in den ersten 60 Tagen ein Guthaben von 200 € bei centron.

Dieses Werbeangebot gilt nur für neue Konten. Angebot ausschließlich für Gewerbetreibende.

Jetzt loslegen Sales kontaktieren