Go Back   Rhinocerus > Newsgroup > Newsgroup comp.lang.* 1 > Newsgroup comp.lang.tcl

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 02-08-2012, 02:05 AM
Peter Prockers
Guest
 
Posts: n/a
Default bgExec - need linux pid

At the moment I am using bgExec and I would use something similar if
needed. http://theory.asu.ru/public/download...i.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?
Reply With Quote
Alt Today
Advertising
 
and become member of Rhinocerus
Standard Sponsored Links

  #2 (permalink)  
Old 02-08-2012, 02:44 AM
Ian Gay
Guest
 
Posts: n/a
Default Re: bgExec - need linux pid

Peter Prockers wrote:

> At the moment I am using bgExec and I would use something similar if
> needed. http://theory.asu.ru/public/download...i.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?


--

If you know the process name you could use pgrep.
(And indeed, you could kill with pkill.)

*********** To reply by e-mail, make w single in address **************
Reply With Quote
  #3 (permalink)  
Old 02-08-2012, 08:05 AM
M. Strobel
Guest
 
Posts: n/a
Default Re: bgExec - need linux pid

Am 08.02.2012 04:05, schrieb Peter Prockers:
> At the moment I am using bgExec and I would use something similar if
> needed. http://theory.asu.ru/public/download...i.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?


Do it like this:

strobel@s114-intel:~> tclsh
% puts "my process id is: [pid]"
my process id is: 3741
%

/Str.
Reply With Quote
  #4 (permalink)  
Old 02-08-2012, 09:30 AM
Alexandre Ferrieux
Guest
 
Posts: n/a
Default Re: bgExec - need linux pid

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...i.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


Reply With Quote
  #5 (permalink)  
Old 02-08-2012, 09:58 AM
M. Strobel
Guest
 
Posts: n/a
Default Re: bgExec - need linux pid

Am 08.02.2012 04:05, schrieb Peter Prockers:
> At the moment I am using bgExec and I would use something similar if
> needed. http://theory.asu.ru/public/download...i.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?


Alex Ferrieux just wrote it, but let me improve my first answer, I checked that myself:

The bgexec from http://wiki.tcl.tk/12704 does an open on a process pipeline, i.e.

open "| myprog"

The manual about open, command pipeline, says: The id of the spawned process is
accessible through the pid command, using the channel id returned by open as argument.

/Str.
Reply With Quote
  #6 (permalink)  
Old 02-08-2012, 03:42 PM
Uwe Klein
Guest
 
Posts: n/a
Default Re: bgExec - need linux pid

Peter Prockers wrote:
> At the moment I am using bgExec and I would use something similar if
> needed. http://theory.asu.ru/public/download...i.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?


from the original blt man page on bgexec:
You can also terminate the program by setting the variable
myStatus. If myStatus is set before du has completed, the
process is killed. Under Unix, this is done sending by a
configurable signal (by default it's SIGKILL). Under
Win32, this is done by calling TerminateProcess. It makes
no difference what myStatus is set to.

there is refactored code from blt around that is accessed
via compilation by way of critcl.
http://wiki.tcl.tk/13400

either use that or copy the SIGKILL functionality ( tclX comes to mind )


uwe
Reply With Quote
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT. The time now is 06:22 AM.


Copyright ©2009

LinkBacks Enabled by vBSEO 3.3.0 RC2 © 2009, Crawlability, Inc.