Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to run many applications at once using socket

2 views
Skip to first unread message

Ronald

unread,
Jun 25, 2002, 7:39:25 PM6/25/02
to
I'd like to run some applications (in this example: run1, run2, run3)
at once.
requirement:
1. The main function will wait until all of these application finish
before it closes.
2. All of these applications (run1, run2, run3) must be run in
parallel.

For a reason I do not understand (related to fconfigure/fileevent?),
the applications run1, run2 and run3 work serially after one another.

If I put "&" after sleep command, the main function will close BEFORE
all applications conclude.

The short code is attached.

Please, would some guru enlighten me ?

thanks,
ron


#!/bin/sh
# \
exec tclsh "$0" "$@"

proc getIP {} {
set server [socket -server "#" 0]
set pn "[lindex [fconfigure $server -sockname] 2]"
set client [socket [info hostname] $pn]
set ip [lindex [fconfigure $client -sockname] 0]
close $client
close $server
return $ip
}

proc run1 { portN ipAdd } {
puts " run1"
set k [socket $ipAdd $portN ]
fconfigure $k -buffering line
set t1 [exec sleep 10 ]
exec ls
puts $k tryrun2
close $k
}

proc run2 { portN ipAdd } {
puts " run2"
set m [socket $ipAdd $portN]
fconfigure $m -blocking 0 -buffering line
set t2 [exec sleep 5 ]
puts $m tryrun2
close $m
}

proc run3 { portN ipAdd } {
puts " run3"
set n [socket $ipAdd $portN]
fconfigure $n -buffering line
set t3 [exec sleep 10 ]
exec ls -la
puts $n tryrun3
close $n
}

proc accept {s a port} {
fileevent $s readable [list echo $s]
fconfigure $s -translation lf -buffering line -blocking 1
puts "connection from $a $port with s = $s"
}

proc echo {s} {
global x
set l [gets $s]
if {[eof $s]} {
puts " will close $s"
close $s
set x done
} else {
puts $s "Echoed: $l"
puts "Echoed to stdout: $l"
}
}


set ip_info [getIP]
set s [socket -server accept 0]
set try "[lindex [fconfigure $s -sockname] 2]"


set a [eval [exec [concat [ run1 $try $ip_info ] >& a.log ]&]]
set b [eval [exec [concat [ run2 $try $ip_info ] >& b.log & ]&]]
set c [eval [exec [concat [ run3 $try $ip_info ] >& c.log ] <@ $s >&@
$s ]]

vwait x;
vwait x;
vwait x;

puts "done ... will close server $s"
close $s

Gerald W. Lester

unread,
Jun 26, 2002, 2:19:07 AM6/26/02
to
Instead of exec you need to check out the open command, pay attention to
the section about the pipe {"|"} symbol.

Ronald wrote:

--
+--------------------------------+---------------------------------------+

| Gerald W. Lester | "The man who fights for his ideals is
|
| Gerald...@cox.net | the man who is alive." -- Cervantes
|
+--------------------------------+---------------------------------------+

Cameron Laird

unread,
Jun 26, 2002, 7:36:06 AM6/26/02
to
In article <3D195CE9...@cox.net>,

Gerald W. Lester <Gerald...@cox.net> wrote:
>Instead of exec you need to check out the open command, pay attention to
>the section about the pipe {"|"} symbol.
.
.
.
Incidentally, your program can be rewritten in about
half the size (and complication). Once you have the
functionality you want, perhaps you'll choose to
check back in for tips on simplification.
--

Cameron Laird <Cam...@Lairds.com>
Business: http://www.Phaseit.net
Personal: http://starbase.neosoft.com/~claird/home.html

0 new messages