Re: threads
From: zentara (zentara_at_highstream.net)
Date: 01/23/05
- Next message: Måns Rullgård: "Re: threads"
- Previous message: David Schwartz: "Re: memory allocation in unix"
- In reply to: Måns Rullgård: "Re: threads"
- Next in thread: Måns Rullgård: "Re: threads"
- Reply: Måns Rullgård: "Re: threads"
- Reply: David Schwartz: "Re: threads"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 23 Jan 2005 07:30:51 -0500
On Sat, 22 Jan 2005 11:33:12 +0100, Måns Rullgård <mru@inprovide.com>
wrote:
>zentara <zentara@highstream.net> writes:
>
>> On Fri, 21 Jan 2005 17:08:25 -0800, "David Schwartz"
>> <davids@webmaster.com> wrote:
>>
>>> It's too bad it's not really practical to use pools of processes the way
>>>you use pools of threads. That would be an another interesting option that
>>>would give you some of the benefits of both and few of the disadvantages of
>>>either. You'd need a library that simplified things like cross-process
>>>synchronization, objects in shared memory, and file descriptor exchange.
>>>Thesis project anyone?
>>
>> Perl has Parallel::Fork::Manager.
>
>Doesn't seem to be in a standard installation.
>I haven't checked, but I'm pretty certain that thing does a fork each
>time you call it. It's rather simple to keep a counter of how many
>processes have been forked, and wait() for some to finish before
>starting more when the limit has been reached.
>
>I think David was wishing for an easy to use library that pre-forked a
>number of processes, and reused the same processes, much like Apache
>httpd does.
Yeah, you are right. But Perl to the rescue. :-)
I would use IPC::Open3 to open a set of stdin,stdout,stderr
pipes to 'bash' or whatever shell you want, then just send
commands to it to run. The fork'd processes would be reusable
and under the control of the parent process( i.e. kill $pid ).
This is just a simple example, (I've combined the stderr and stdout
to avoid needing to use select). I could have forked more than 1
and I could change the command to send to the bash interpreter
for each refresh.)
I know you fellows prefer to discuss C, but Perl does make alot
of difficult things easy.
#!/usr/bin/perl
use warnings;
use strict;
use IPC::Open3;
use Tk;
$|=1;
my $pid=open3(\*IN,\*OUT,0,'/bin/bash');
my $mw=new MainWindow;
$mw->geometry("600x400");
my $t=$mw->Scrolled('Text',-width => 80,
-height => 80,
)->pack;
&refresh;
$mw->fileevent(\*OUT,'readable',\&write_t);
my $id = Tk::After->new($mw,2000,'repeat',\&refresh);
MainLoop;
sub refresh{
print IN "top b n 1";
print IN "\n"; #absolutely needed and on separate line
}
sub write_t {
my $str= <OUT>;
$t->insert("1.0",$str);
# $t->see("0.0");
}
__END__
-- I'm not really a human, but I play one on earth. http://zentara.net/japh.html
- Next message: Måns Rullgård: "Re: threads"
- Previous message: David Schwartz: "Re: memory allocation in unix"
- In reply to: Måns Rullgård: "Re: threads"
- Next in thread: Måns Rullgård: "Re: threads"
- Reply: Måns Rullgård: "Re: threads"
- Reply: David Schwartz: "Re: threads"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|