0

haven't used nohup command until today, but now I need to use it to run a command in the background.

As far as i know, i can also use the bg command to run a process in background. So my question is, what are the differences between nohup and bg commands?

Akhil S
  • 101
  • 2
  • https://stackoverflow.com/questions/15595374/whats-the-difference-between-nohup-and-ampersand – Artem S. Tashkinov Feb 11 '21 at 08:09
  • 1
    Does this answer your question? [Why does my application die without nohup?](https://unix.stackexchange.com/questions/196755/why-does-my-application-die-without-nohup) – muru Feb 11 '21 at 13:05
  • Also related: [How to “correctly” start an application from a shell](https://unix.stackexchange.com/q/152310/80216)  Disclosure: I am the author of the accepted answer. – G-Man Says 'Reinstate Monica' Feb 12 '21 at 18:41

1 Answers1

1

Running a command in the background allows you working on in that shell, but does NOT prevent the command from being killed once you exit the session (e.g. log out from the desktop session, end an ssh-session, exit the tty).

nohup is meant for starting long-running processes that should run on a server even when the user logs out.

FelixJN
  • 12,616
  • 2
  • 27
  • 48
  • 2
    To add to this, `nohup` is short for **no hang up** which prevents the process from receiving the `SIGHUP` or **Signal Hang UP** signal -- which is the signal sent when closing/exiting the terminal. – clownbaby Feb 12 '21 at 00:13