How to start a stopped process in Linux
I have a stopped process in Linux at a given terminal. Now I am at another ter开发者_StackOverflow中文版minal. How do I start that process. What kill signal would I send. I own that process.
You can issue a kill -CONT pid, which will do what you want as long as the other terminal session is still around. If the other session is dead it might not have anywhere to put the output.
In addition to @Dave's answer, there is an advanced method to redirect input and output file descriptors of a running program using GDB.
A FreeBSD example for an arbitrary shell script with PID 4711:
> gdb /bin/sh 4711
...
Attaching to program: /bin/sh, process 4711
...
(gdb) p close(1)
$1 = 0
(gdb) p creat("/tmp/testout.txt",0644)
$2 = 1
(gdb) p close(2)
$3 = 0
(gdb) p dup2(1,2)
$4 = 2
EDIT - explanation: this closes filehandle 1, then opens a file, which reuses 1. Then it closes filehandle 2 and duplicates filehandle 1 to 2.
Now this process' stdout
and stderr
go to indicated file and are readable from there. If stdin
is required, you need to p close(0)
and then attach some input file or PIPE or smth.
For the time being, I could not find a method to remotely disown
this process from the controlling terminal, which means that when the terminal exits, this process receives SIGHUP
signal.
Note: If you do have/gain access to the other terminal, you can disown -a
so that this process will continue to run after the terminal closes.
精彩评论