[email protected]Support 24/7 · Billing 09:00 – 00:00LinkedInXFacebook
NexonHost
Netherlands Dedicated ServersAmsterdam · Equinix AM6Germany Dedicated ServersFrankfurt · Equinix FR4Romania Dedicated ServersBucharest · VoxilityAustria Dedicated ServersVienna · Interxion VIEBulgaria Dedicated ServersSofia · TelepointFrance Dedicated ServersParis · Interxion PAR — Marseille · Digital Realty MRS3Ireland Dedicated ServersDublin · Equinix DB2Italy Dedicated ServersMilan · Irideos AvalonPoland Dedicated ServersWarsawSpain Dedicated ServersMadrid · Equinix MD2United States Dedicated ServersAshburn · Equinix DC
All articles
Getting startedMay 2, 2023

How to use nohup command.

How To Use Nhup Command.

The nohup command executes another program specified as its argument and ignores all SIGHUP (hangup) signals. SIGHUP is a signal that is sent to a process when its controlling terminal is closed.

Usually, when you run a program over SSH, if your connection drops or you log out, the session is terminated, and all the processes executed from the terminal will stop. This is where the nohup command comes in handy. It ignores all hangup signals, and the process will continue to run.

 

How to Use the nohup Command

The syntax for the nohup command is as follows:

nohup COMMAND [ARGS]

The command doesn’t accept any other options except the standard –help and –version.

Let’s take a look at the following example:

nohup mycommand
nohup: ignoring input and appending output to 'nohup.out'

nohup runs the mycommand command in the foreground and redirects the command output to the nohup.out file. This file is created in the current working directory . If the user running the command doesn’t have write permissions to the working directory, the file is created in the user’s home directory.

If you log out or close the terminal, the process is not terminated.

 

Running the Command in Background

Using nohup in the foreground is not very useful because you won’t be able to interact with the shell until the command completes.

To run the command in the background, append the & symbol at the end of the command:

nohup mycommand &

The output includes the shell job ID (surrounded with brackets) and process ID:

[1] 25177

You can use the job ID to bring the command into the foreground using the fg command.

If for some reason you want to terminate the process, use the kill command followed by the process ID:

kill -9 25132

 

Redirecting Output to a File

By default, nohup redirects the command output to the nohup.out file. If you want to redirect the output to a different file, use the standard shell redirection.

For example, to redirect the standard output and standard error to the mycommand.out you would use:

nohup mycommand > mycommand.out 2>&1 &

To redirect the standard output and standard error to different files:

nohup mycommand > mycommand.out 2> mycommand.err &

 

Alternatives

There are several alternative programs that you can use to avoid a command to be terminated when you close the terminal or get disconnected.

 

Screen

Screen or GNU Screen is a terminal multiplexer program that allows you to start a screen session and open any number of windows (virtual terminals) inside that session. Processes running in Screen will continue to run when their window is not visible even if you get disconnected.

 

Tmux

Tmux is a modern alternative to the GNU screen. With Tmux, you can also create a session and open multiple windows inside that session. Tmux sessions are persistent, which means that programs running in Tmux will continue to run even if you close the terminal.

 

Disown

disown is a shell builtin that removes a shell job from the shell’s job control. Unlike nohup, you can use disown on running processes too.

 

Conclusion

nohup allows you to prevent commands from being terminated when you log out or exit the terminal.

Keep reading
How to Install Ubuntu 20.04 on Windows 10.
March 23, 2023

How to Install Ubuntu 20.04 on Windows 10.

NOTE: If you want to learn Linux (ubuntu), this is a very good and simple way to learn, I hope you like this article. Ubuntu is a very stable and flexible operating system and a Debian-based Linux distribution consisting mainly of free and open-source software. There are different versions of…

Read article
How to Find/Get your IP Address
March 23, 2023

How to Find/Get your IP Address

How To Find/Get Your IP Address This article explains several different methods of determining the public and private IP Addresses of a Linux system. Knowing the IP address of your device is important when troubleshooting network issues, setting up a new connection, or configuring a firewall. IP…

Read article
How to Add User to Sudoers in CentOS
March 23, 2023

How to Add User to Sudoers in CentOS

How To Add User To Sudoers In CentOS sudo is a command-line utility designed to allow trusted users to run commands as another user, by default the root user. You have two options to grant sudo access to a user. The first one is to add the user to the sudoers file . This file…

Read article
Get in Touch

Together, Let’s Build a Faster, Safer Internet.

Build scalable infrastructure with NexonHost — high-performance dedicated servers, VPS hosting, cloud hosting, and DDoS protection across Europe.

Get Started →Contact Us
[email protected]Support 24/7 · Billing 09:00 – 00:00