unix – run/send process in the background

Below are a few ways of achieving that

Option1: nohup

With nohup (no-hangup):

nohup <command-line> > <to_file.out> &

(use >> to append)

Option 2: pause/restart as background process

Issue is when you need to provide some user inputs.
In that case, proceed as follows:

  1. Run CLI as per normal and provide required user input
  2. Once no more input is required, hit ctrl+Z to stop/pause the job
  3. Run following command to identify your job id (different from pid):

    Note: in above screenshot my job_id would be “1”

  4. Disown the process:
    disown -h %<job_id>

    Note: “%” is required

  5. Resume process:
    bg %<job_id>

    Note: “%” is required

Option 3: screens



Post a Comment

Your email is never published nor shared. You're allow to say what you want...