On Feb 8, 4:05 am, Peter Prockers <
peter.prock...@googlemail.com>
wrote:
> At the moment I am using bgExec and I would use something similar if
> needed.
http://theory.asu.ru/public/download/sites/wiki.tcl.tk/12704
>
> The process I run will run forever, unless killed. Even if the file
> channel is closed, the process remains running.
>
> To kill the process I would need to know pid, which I can see with ps
> ux in linux console.
>
> How can I get the linux pid (ps ux) after starting a process? I could
> phrase "ps ux" before and after bgExec but I am looking for a more
> elegant way. How to do it?
set ff [open "|some command w"]
set p [pid $ff]
close $ff
Note that if "some command" is a shell script, killing it will not
necessarily affect its children.
Two approaches to this problem:
(1) arrange for 'some command' to remain the important process to
kill. Typically to do this in a shell script, you do all your
preparations in sh, then end with "exec foo bar baz ..." (this is sh's
exec, not Tcl's).
(2) use 'setsid' to allocate a new process group, which will be -$p,
and kill the group:
set ff [open "|setsid some command w"]
set p [pid $ff]
close $ff
(later)
kill -$p
-Alex