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

Detecting if a tcl shell instance is also running on this machine.

42 views
Skip to first unread message

S-Y. Chen

unread,
Jun 17, 2013, 11:08:22 AM6/17/13
to
Hi all,

I am currently customizing the tcl c source code for my own application .

When my own tcl shell is running on a computer, is it possible to detect if another instance of (my own) tcl shell is also running on the same computer ?

I am not talking about multi-thread in a tcl shell instance. I am hoping to detect multiple instance of (my own) tcl shell on a same computer.

Any help will be greatly appreciated.

Regards
S-Y. Chen

Don Porter

unread,
Jun 17, 2013, 11:18:40 AM6/17/13
to
On 06/17/2013 11:08 AM, S-Y. Chen wrote:
> When my own tcl shell is running on a computer, is it possible to detect if another instance of (my own) tcl shell is also running on the same computer ?

http://wiki.tcl.tk/1558


--
| Don Porter Applied and Computational Mathematics Division |
| donald...@nist.gov Information Technology Laboratory |
| http://math.nist.gov/~DPorter/ NIST |
|______________________________________________________________________|

Ted Nolan <tednolan>

unread,
Jun 17, 2013, 11:46:09 AM6/17/13
to
In article <943fcfdc-aef6-475a...@googlegroups.com>,
I looked at this a while ago and one of the solutions I found on
the wiki was to open a server socket on a particular port (you don't
actually have to do anything with connections). This can only
succeed in one process at a time.


# pick a server port number not in use on your system
set myport 123456

if {[catch {socket -server {} -myaddr {127.0.0.1} $myport} err] } {
puts "Detected already running instance, exiting.."
exit 0
}
--
------
columbiaclosings.com
What's not in Columbia anymore..

S-Y. Chen

unread,
Jun 17, 2013, 12:16:18 PM6/17/13
to

Actually instead of locking into only one instance, I would like to count how many instances are already in the machine.

Is it possible to do that ?

Regards
Chen

Uwe Klein

unread,
Jun 17, 2013, 1:08:28 PM6/17/13
to
on unix yes:
# create an interpreter and put it into the background:
uwe@ben:~/dwnlds> tclsh
%
[1]+ Stopped tclsh
# create another shell and start introspecting:
uwe@ben:~/dwnlds> tclsh
% info nameofexecutable
/usr/bin/tclsh
% exec fuser -v /usr/bin/tclsh

USER PID ACCESS COMMAND
/usr/bin/tclsh uwe 8518 ...e. tclsh
uwe 8523 ...e. tclsh
uwe 19831 ...e. tclsh
uwe 31415 ...e. tclsh

# then you could look for all users of the tcl$version librarie:
% exec ldd /usr/bin/tclsh
linux-gate.so.1 => (0xffffe000)
libtcl8.4.so => /usr/lib/libtcl8.4.so (0x40038000)
libdl.so.2 => /lib/libdl.so.2 (0x400e0000)
libm.so.6 => /lib/tls/libm.so.6 (0x400e3000)
libc.so.6 => /lib/tls/libc.so.6 (0x40106000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
% exec fuser -v /usr/lib/libtcl8.4.so

USER PID ACCESS COMMAND
/usr/lib/libtcl8.4.so
uwe 8518 ....m tclsh
uwe 8523 ....m tclsh
uwe 19831 ....m tclsh
uwe 31415 ....m tclsh
%
you can't see 'kit'ted interpreters
or anything else that has been statically linked to libtcl.a

uwe
0 new messages