Quick workout:

To Stop/Suspend, Resume, Re-Parent, Move process across shell/init.

  • Suspend the process using ‘ctrl + z’
  • Move the process to background using ‘bg’
  • Re-parent the process to init using ‘disown %<job_id>’. Job_id can be listed using ‘jobs’
  • Now the process is under init.
  • or reptyr <pid to move> (Run from the destination shell)

Detailed description:

My git clone request simply stalls all my bandwidth in the router (no sure why. Still looking out for reason). When I was updating and cloning the repository, no one in my network was able to work on the internet. So I simply Suspended/Stopped the process by ‘Ctrl + z’ (Refer Quick CLI tips).

I was wondering there could be some option to resume my work even after exiting the current shell. Yes, i might have used ‘nohup’ while starting ‘git clone’. But how can i ‘nohup’ to the running/suspended process which is already started without ‘nohup’?

I resumed the suspended/stopped process using ‘bg’ and ‘disown %<jobid>’ (which can be listed used ‘jobs’ command) to re-parent to init. In my Ubuntu it was re-parented to ‘init –user’ (not sure why. Upstart is doing some trick here).

Note: For all the bash built-in commands (can be identified with ‘type <command>’ e.g. ‘type disown’ will show “disown is a shell builtin”) help can be read using ‘help <built-in command>’

Alternative way:

A better alternative is to the above process would be ‘reptyr’. Reptyr will re-parent the running process from one shell to another without disturbing the execution. Reptyr uses ptrace(2) to achieve this.

Usage: reptyr <PID to be re-parented> (Run this command the destination shell where you want to move the process)

The overhead here is to install ‘reptyr’ which doesn’t come by default or built-in to shell.