How to quit ESXi SSH and leave background tasks running

In Linux when a console session is closed most background jobs (^Z and bg %n) will stop running when the parent ( the ssh session ) is closed because the parent sends a SIGHUP to all its children when closing (properly). Some programs can catch and ignore the SIGHUP or not handle it at all hence passing to the root init parent. The disown command in a shell removes a background job from the list to send SIGHUPs to.

In ESXi there is no disown command. However there is a way to close a shell immediately without issuing the SIGHUPs :

exec </dev/null >/dev/null 2>/dev/null

The exec command will run a command and switch it out for the current shell. Also this command will make sure the stdio and stderr are piped properly.

nJoy 😉

4 Replies to “How to quit ESXi SSH and leave background tasks running”

  1. Hello,

    I came across your page while researching a similar issue I am having. I need to SSH into ESXi, execute a command, exit SSH session. All while not killing the process associated with the executed command. I am trying to figure out how to use the above example in your article. Is this the way you can exit the SSH session without the process being terminated as well? I have tried using it, but am getting the same results. Any help would be appreciated.

    1. Sorry it was not clear..
      The idea is to run the commands in the job list, say

      $cp /path1/file1 /path2/file2 & 
      

      Then when you need to log off the session you run the

      $exec </dev/null >/dev/null 2>/dev/null 
      

      When leaving the session the SIGHUPs to child processes will (or should , ESX is bound to change userspace without notice) NOT be sent.
      Hope this clarifies a bit..

      The piped output is lost as this is but you could replace the >/dev/null 2>/dev/null to point to log files instead of discarding. Ijust hate doing that on ESX as it is not clear what the effects are if the storage location / path where you point the pipes is not writable or unavailable.

      😉

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.