🍎 Why isn’t “nohup” working on macOS?

Ido Montekyo
idomongo
Published in
2 min readSep 29, 2021
Photo by Patrick Ward on Unsplash

If you are working with Linux you are probably using the nohup command.

nohup is a POSIX command which means “no hang-up”. Its purpose is to execute a command such that it ignores the HUP (hangup) signal and therefore does not stop when the user logs out.

nohup is how I am able to run commands/apps/jobs in a terminal session in the background so when I am closing the terminal session, the process remains running in the background.

However, for some reason, this is not working for me on macOS.

For example, I wrote the following script:

  1. Kill Microsoft Teams process
  2. Delete Microsoft Teams local cache directory
  3. Relaunch Microsoft Teams app
ps -ef | grep teams | cut -d " " -f2 | xargs kill -9sleep 3rm -rf "/Users/me/Library/Application Support/Microsoft/Teams"nohup "/Applications/Microsoft Teams.app/Contents/MacOS/Teams" &

But each time this script finished executing and the terminal window is closed, the Microsoft Teams app is terminated as well.

Using the screen command instead of nohup didn’t work as well and the only workaround I’ve found for this is using the open command:

ps -ef | grep teams | cut -d " " -f2 | xargs kill -9sleep 3rm -rf "/Users/me/Library/Application Support/Microsoft/Teams"open -a "/Applications/Microsoft Teams.app/Contents/MacOS/Teams"

Now the script finished executing yet the Teams app is still running in the background.

🐈‍⬛

--

--

Ido Montekyo
idomongo

System Analysis. System Design. Architecture. Databases. Project Management. Speaker. People Motivator.