| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | File Handles |
PE> > JdeBP> Ever written a daemon process ? What's the first thing that a > JdeBP> well-written background daemon process does ? That's right. It > JdeBP> closes any open file handles that it may have accidentally > JdeBP> inherited. > > Ok, so how do you do this properly? for (x = 0; x < > ULONG_MAX; x++) DosClose(x); PE> I'd use the value obtained by DosQueryRelMaxFH (with a delta of zero) as the highest file handle. Other than that, yes. PE> > ??? And there's definitely nothing wrong with closing file > handles that have NEVER been opened? PE> The DosClose call will simply return an error, indicating that the file handle wasn't open in the first place. PE> > And nothing wrong > with closing a file handle which may have been fopen'd by a > previous process, and still has data in the buffer, which > needs to be flushed to disk? PE> It will still be open in the parent process. Each process has its _own_ file handle table, over which it has complete and exclusive control. When a child process inherits open files from its parent, what happens is that the file handle table from the parent is copied to the table for the child, and each entry in the _system_ file table (to which the entries in the per-process file handle tables point) has its usage counter incremented. Closing the file handle in the child will decrement the SFT use counter again, but since it was incremented that won't invalidate the pointer to that SFT entry in the parent's per-process file handle table. This is how things operate internally, of course. A process cannot access the SFT directly. As far as each process is concerned, it has a set of 0..N file handles, which it inherits from its parent when first created, but over which from then on it has complete, absolute, and exclusive control. > JdeBP < ___ X MegaMail 2.10 #0: --- Maximus/2 3.01* Origin: DoNoR/2,Woking UK (44-1483-725167) (2:440/4) SEEN-BY: 270/101 711/401 409 410 413 430 808 809 934 955 712/407 515 624 628 SEEN-BY: 713/317 @PATH: 440/4 141/209 270/101 712/515 711/808 934 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.