[comp.unix.questions] Driver close system call

williamt@babel.SanDiego.NCR.COM (Wm. Tseng) (03/30/89)

I have a question about driver close routine. Thanks in advance for any answer.

  If a process exits or terminates before it closes a driver, does kernel close
the driver for that process ? In user process, several processes can open the 
same driver. Are driver open and close routines executed as many time as process
calls it ? Does kernel control the close system call, so close is only executed
once (when last process closes it)? When system crash, does kernel close all 
the opened file and driver or just leave them open ?

					william
					williamt@babel.sandiego.ncr.com
 

rogerc@ncrcae.Columbia.NCR.COM (Roger Collins) (03/30/89)

In article <1193@ncr-sd.SanDiego.NCR.COM> williamt@babel.SanDiego.NCR.COM (Wm. Tseng) writes:
> 
> If a process exits or terminates before it closes a driver, does kernel close
> the driver for that process ?

Yes.  All files (includes device nodes, regular files, pipes, etc.) are closed.

> In user process, several processes can open the 
> same driver. Are driver open and close routines executed as many time as process
> calls it ?

Yes and no.  Yes for opens, no for closes.  All opens get to the driver.
Only the last close gets to the driver.

> Does kernel control the close system call, so close is only executed
> once (when last process closes it)?

You got it, but not to confuse anyone else:  You meant to say,

"...so *the driver's* close is only executed once..."

The kernel does execute close logic for every close system call 
(decrement the reference counter for example), it just doesn't call the
driver's close routine until the reference counter is zero.

> When system crash, does kernel close all 
> the opened file and driver or just leave them open ?

No.  The kernel leaves everything basically as is (except for syncing
the drives).  This is probably vendor specific; I know only about
the NCR TOWER.

--
Roger Collins
NCR - E&M Columbia
rogerc@ncrcae.Columbia.NCR.COM

rogerc@ncrcae.Columbia.NCR.COM (Roger Collins) (03/30/89)

In article <4337@ncrcae.Columbia.NCR.COM> I write:
> 
> Yes.  All files (includes device nodes, regular files, pipes, etc.) are
> closed.

Oops.  The question was does the kernel close the *driver* when a process
terminates?  The answer is clear if you read the rest of my posting,
but just in case:

All the files opened by the process are closed.  If the file that is
the device node for the driver is closed and the reference count is
zero (last close for the device), then... yes, the driver gets closed
when the process terminates.  Otherwise no.