I've been asked how to do something I'm at a loss as to where to start
- if it's possible at all. To quote the person asking me:
Is there a way 1. to check the state of a port, 2. determine the application using it?
By #1, I believe he means "determine if a comm port was in use".
Any ideas whatsoever would be appreciated. I believe #1 can be done
by an attempt to open the port as a file in "DENY_ALL" mode - if it
fails, someone is using it. I don't believe #2 is possible. If I
could be corrected, that would be great. :-)
I've been asked how to do something I'm at a loss as to where to
start - if it's possible at all. To quote the person asking me:
Is there a way 1. to check the state of a port, 2. determine the
application using it?
By #1, I believe he means "determine if a comm port was in use".
Any ideas whatsoever would be appreciated. I believe #1 can be done
by an attempt to open the port as a file in "DENY_ALL" mode - if it
fails, someone is using it. I don't believe #2 is possible. If I
could be corrected, that would be great. :-)
Get OS2UNDOC from hobbes and have a look at the DosQuerySysState API.
It will return infos about all open files of a single or all
processes. There are problems when using it at certain fixpak levels (older Warp 3 fixpaks).
And Scott Garfinkle posted in C.O.O.P.Misc that it is now possible
getting infos about all open semaphore handles as well. Starting
with FP 13 AFAIR (got the msg stored somewhere).
Is there a way 1. to check the state of a port, 2. determine the
application using it?
By #1, I believe he means "determine if a comm port was in use".
Any ideas whatsoever would be appreciated. I believe #1 can be done
by an attempt to open the port as a file in "DENY_ALL" mode - if it
fails, someone is using it. I don't believe #2 is possible. If I
could be corrected, that would be great. :-)
Get OS2UNDOC from hobbes and have a look at the DosQuerySysState API.
It will return infos about all open files of a single or all
processes. There are problems when using it at certain fixpak
levels (older Warp 3 fixpaks).
Of course! I forgot all about that. I already use that call for a
number of things, so one more is no biggie. :-) Unfortunately, I
can't figure out how to trace back from the file to the process(es).
I've done some slight modifications to the sample programs given in...
the undoc INF file, and I get:
name: D:\BBS\MAIL\ECHO\FIDONET\BACKBONE\OS2PROG.SQD
opencnt: 1
sfn: e0
refcnt: 1
flags: 0
accmode: c2
filesize: 62315
volhnd: 264
attrib: 20 [A-----]
Now, *I* know which process this is:
PID: 1736
PPID: 30
type: 3
state: 10
session id: 36
mod handle: 1be8 (D:\BBS\FLEET\FLTSTRT.EXE)
# of threads: 4
[...]
I just can't tell how to get from one to the other.
Get OS2UNDOC from hobbes and have a look at the DosQuerySysState
API. It will return infos about all open files of a single or all
processes. There are problems when using it at certain fixpak
levels (older Warp 3 fixpaks).
Of course! I forgot all about that. I already use that call for a
number of things, so one more is no biggie. :-) Unfortunately, I
can't figure out how to trace back from the file to the process(es).
Use the brute force method? See below.
There is this lees-than-optimal solution but why not use it:
get a list of all running processes via DosQuerySysState
for every process ID
get a list of all open files via DosQuerySysState
for every open file
check whether filename = COMx
if identical
dump process info (DosQuerySysState)
I don't think it would be too slow to be usable.
Of course - didn't think of that. However, I've found what may work a
bit better, if I can decipher everything. The Warp4.5 toolkit *has* DosQuerySysState somewhat documented, and some of its structures are
a bit bigger than what OS2UNDOC has. Unfortunately, I don't have
that toolkit at home... :-/
Sysop: | digital man |
---|---|
Location: | Riverside County, California |
Users: | 1,041 |
Nodes: | 17 (0 / 17) |
Uptime: | 13:09:08 |
Calls: | 501,715 |
Calls today: | 8 |
Files: | 104,421 |
D/L today: |
6,152 files (2,350M bytes) |
Messages: | 298,459 |
Posted today: | 2 |