K_M_McMahon has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks! I humbly request your assistance.

I am just learning TK and I have not been able to find a comprehensive source of information (I'm planning on buying a book tomorrow).

Here's what I'm working on, I am desinging a script to act as a control panel which can monitor, start and stop certain scripts that I want running on my machine. I have gotten the raw gui designed, I have the start and stop buttons designed.

What I can't figure out is the monitor widget. I want a block/widget/button that will show red when a specific script is not running and green when the script is running. I can design a subroutine that can do a "ps -ef|grep" and determine if the script is running, but how do I have the little subroutine running all the time and updating the widget so that it gives a visual display of the background script's status?


THANX! for any help you can give! -Kevin

Replies are listed 'Best First'.
Re: Tk process monitoring
by zentara (Cardinal) on Apr 03, 2004 at 14:26 UTC
    There are alot of ways to do this, and I'll bet if you search groups.google.com, you will find solutions.

    As far as green and red indicators go, you can use just about any widget you want, and $widget->configure(-bg =>'green') and (red) at the appropraite times. The label is probably the smallest widget (as far as code size goes), but the CheckButton would be easy too, as it would let you label it too.

    You will need to use a Tk::after or Tk::repeat to run your ps-test after a delay. But you can run it thru system, or check out Tk::ExecuteCommand.


    I'm not really a human, but I play one on earth. flash japh

    edited: Sun Apr 4 04:39:00 2004 by jeffa - added readmore

•Re: Tk process monitoring
by merlyn (Sage) on Apr 03, 2004 at 10:46 UTC
    Unless you actually started the other process yourself, and will be getting child-exit notification when the process is complete, you'll need to poll. In Tk, polling is performed using the after and repeat mechanisms. So, once you've set a button to green, set up an after-trigger so that 5 seconds later it attempts a kill 0 to the process ID. If that succeeds, then it's still alive, so set up the after-trigger again, but if not, set it to red.

    I do encourage you though to take a serious look at using POE and Tk together. Tk's timeslicing is fairly simple: POE brings a lot of reusable timesliced tools to the picture, so your wheel invention is far less and easier.

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

Re: Tk process monitoring
by K_M_McMahon (Hermit) on Apr 03, 2004 at 18:13 UTC
    Thanx for your help! The final code is below! it works now!!
Re: Tk process monitoring
by DaWolf (Curate) on Apr 03, 2004 at 09:23 UTC
    Hi.

    Sorry I can't give you an answer (I wish I knew), but you can take a look at front end language, you may find something useful there.

    Best regards,

    my ($author_nickname, $author_email) = ("DaWolf","erabbott\@terra.com.br") if ($author_name eq "Er Galvão Abbott");