[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference noted::hackers_v1

Title:-={ H A C K E R S }=-
Notice:Write locked - see NOTED::HACKERS
Moderator:DIEHRD::MORRIS
Created:Thu Feb 20 1986
Last Modified:Mon Aug 03 1992
Last Successful Update:Fri Jun 06 1997
Number of topics:680
Total number of notes:5456

308.0. "WHOSE GOT THE FILE OPEN???" by PMRV70::AVDEV () Thu Sep 11 1986 13:43

    	Does anyone know of a way to find out what users have have
    	a particular file open without using SH DEV/FILES?
    
    	Here's the situation:  I have an a batch job that runs a
    	COBOL program that needs to lock a data file.  This job is
        part of a large application that uses explicit file and
    	record locking (ie: APPLY LOCK-HOLDING).  When the batch
    	job starts up the particular file might already be opened
    	by another user.  The application is used 24 hours a day
    	so I can't necessarily by sure the file will be accessible
    	for locking at some odd hour like 2 AM.
    
    	Does anyone know of any RMS utilities or System Service
    	routines that can tell me who has a file open so I can send
    	them a message to free up the particular file.  I am currently
    	SPAWNing to creating a file using SH DEV/FILES/NOSYS and then
    	searching this file to determine whose got the data file open.
    
    	I'm looking for a more elegant way of doing this.  Something
    	that would be performed in a loop (like a $GETJPI wildcard
    	operation) that would return one username at a time when
    	qiven an RMS file spec.
    
    	Any ideas?  Or am I asking too much?
    
    	Thanks
    
    			Ed...
    
    
T.RTitleUserPersonal
Name
DateLines
308.1Write some codeBARAKA::LASTOVICANorm LastovicaThu Sep 11 1986 17:075
    Can be done.  Just do what SHOW DEV/FIL does.  Though I haven't
    looked, I'd imagine that it gets the FCB's (right structure?) for
    the device and just chains through them.  You'll need CMK and will
    have to run at elevated IPL (I think).  Look at the code in the sources
    and see what it takes.
308.2the SPAWN can be done from your programAVANTI::OSMANand silos to fill before I feep, and silos to fill before I feepThu Sep 11 1986 19:1811
    Maybe SHOW DEV/FILE will work for you anyway.
    
    If you're objection to it is that you were having to manually spawn,
    perhaps you'd be satisfied if the SPAWN and the parse all happened
    from a subroutine called by your program.
    
    SPAWN/NOLOGI/NOSYM is reasonably fast, and SHOW DEV/FILE has the
    advantage over the FCB method that you don't need privileges to
    do it.
    
    /Eric
308.3For best results, use a lock (works in a cluster)NOVA::NELSONJENelsonFri Sep 12 1986 13:3410
    These solutions won't work if the process which has the file open
    is on another node in a cluster, since SHOW DEV/FILE only shows
    you the open files on your current node.
    
    You ought to write the application to take out a lock before it
    opens the file.  If another user tries to run the application, it
    can detect that the lock exists, and can notify the other process
    to exit.
    
    				JENelson
308.4I second .3's motionFROST::HARRIMANHarriman, Paul J., qty 1Fri Sep 12 1986 17:3727
    re: .1 and .3
    
     .1's approach requires running at IPL$_SYNCH, since
    you will have to chase the device UCB down, then work your way around
    eventually through the VCBs to the FCB's and tie them back to
    a process. I'm not an expert on this (but have navigated around
    it somewhat) but it is a LOT of work, and hard to debug (IPL$_SYNCH
    is above the debugger's IPL).
    
    .3's approach, on the other hand, requires some changing of the
    application itself. The original application will most likely take
    out locks anyway. However, since we don't know the database management
    system being used, (DBMS, RMS, RDB, ???) we don't really know how
    the locking is being performed. Nor do we know whether or not we
    are on a cluster...(hint, .0 :=) Anyway, if you can't change the
    application, it makes more sense just to look at the locks. There
    are system calls (and library calls too) to look at who owns a lock,
    and it can be accomplished in a higher level language than macro
    since you wouldn't need to SETIPL or anything like that (the system
    service would do it for you)...
    
    Look into $GETLKI. This is not an "easy" system call to use, but
    it is effective. The "lock checking" program only needs to find
    locks if it can't open the file outright. The system does most of
    the work that way.
    
    
308.5Yes, but locks don't always work eitherSQM::HALLYBAre all the good ones taken?Tue Nov 04 1986 16:0521
    The file lock is of the form:
    
    F11B$a<label><file-number>
    
    Where <label> is the volume label, blank-padded to 12-characters
    and <file-number> is a longword representation of the file number
    part of the file ID.  (The first number in the FID triplet).
    
    This lock is taken out in Kernel mode, so to $GETLKI it you need
    to be running in K-mode.
    
    Unfortunately (for this need) the above only holds for VAXCLUSTER=1.
    If you boot with VAXCLUSTER=0 then the XQP does not take out any
    file locks; it uses the FCB as did the ACP in V3 days.
    
    Also, the <label> definition only holds for cluster-mounted disks.
    For privately-mounted volumes there is a combination <nodename>
    and <UCB address> that is formed.  You'll have to use SDA to figure
    out the format if you need to know it.
    
      John