4

Is it possible to foreground a process started by upstart?

root@me:~# ps aux | grep my-app
root      2208  0.2  0.0   1456   480 ?        S    17:38   0:01 /opt/me/my-app
root@me:~# fg 2208
-bash: fg: 2208: no such job
root@me:~# fg $(pidof my-app)
-bash: fg: 2208: no such job

2 Answers 2

7

fg needs a job number, not a PID. There's no job number you can use because any process started by upstart is not a child of your shell. It won't appear in jobs output.

Try reptyr, e.g.:

reptyr 2208

From its man page:

reptyr is a utility for taking an existing running program and attaching it to a new terminal.

Don't miss this note:

reptyr depends on the ptrace(2) system call to attach to the remote program. On Ubuntu Maverick and higher, this ability is disabled by default for security reasons. You can enable it temporarily by doing

echo 0 > /proc/sys/kernel/yama/ptrace_scope

as root, or permanently by editing the file /etc/sysctl.d/10-ptrace.conf, which also contains more information about this setting.

(Read more in this another answer of mine.)

Also note reptyr only attaches a process to another terminal. This does not mean the process becomes a child of your current shell.

1
  • Thanks for the answer but it does not seem to work for ffmpeg. Not sure why though. I get the error "Unable to open the tty in the child." For both the primary and child PIDs.
    – Macindows
    Commented Dec 26, 2019 at 15:32
1

The fgcommand needs the job_id not the process id, you need to run the jobs command and get the job_id of the process

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .