Skip to main content
Héctor Cortiguera
Participating Frequently
May 21, 2024 5:19 AM UTC

Getting users that are locking a file

Hi all

We want to know which users are locking a file.

What we do now:

1- Execute LIST.READU. We can get the PID of the session that is locking the file.

2- With this PID we can execute a LISTU command or run a ps BASH command

3- Parse the output so we can pair PIDs and usernames

This is quite convoluted, and, also, we have discovered that the LIST.READU output has changed in the newer Universe version (even with the INTERNAL parameter) so we have to keep check of the system version to get the PIDs.

Is there a way to ask the system what are the users that are locking a file?



------------------------------
Héctor Cortiguera
Quiter Servicios Informaticos SL
------------------------------

    4 replies

    Manu Fernandes
    Inspiring
    May 21, 2024 7:21 AM UTC

    Hi all

    We want to know which users are locking a file.

    What we do now:

    1- Execute LIST.READU. We can get the PID of the session that is locking the file.

    2- With this PID we can execute a LISTU command or run a ps BASH command

    3- Parse the output so we can pair PIDs and usernames

    This is quite convoluted, and, also, we have discovered that the LIST.READU output has changed in the newer Universe version (even with the INTERNAL parameter) so we have to keep check of the system version to get the PIDs.

    Is there a way to ask the system what are the users that are locking a file?



    ------------------------------
    Héctor Cortiguera
    Quiter Servicios Informaticos SL
    ------------------------------
    Hi

    I suggest doing in BASIC a READU... LOCKED


    Then read STATUS() func which return pid/pib havi g the lock.

    Then use USERINFO() to define who is..

    I hope this help.

    Manu


    Manu

    Neil Morris
    Rocketeer
    May 21, 2024 7:55 AM UTC

    Hi all

    We want to know which users are locking a file.

    What we do now:

    1- Execute LIST.READU. We can get the PID of the session that is locking the file.

    2- With this PID we can execute a LISTU command or run a ps BASH command

    3- Parse the output so we can pair PIDs and usernames

    This is quite convoluted, and, also, we have discovered that the LIST.READU output has changed in the newer Universe version (even with the INTERNAL parameter) so we have to keep check of the system version to get the PIDs.

    Is there a way to ask the system what are the users that are locking a file?



    ------------------------------
    Héctor Cortiguera
    Quiter Servicios Informaticos SL
    ------------------------------

    Hi Hector,

    I'm not sure if the following meets your requirements, but if you do a READU using the LOCKED clause, the STATUS() returns the user holding the lock. And the USERINFO() function and LISTUSER command can be used to return additional information.

    >COPYP BP LOCK.TEST2 (TSN

         LOCK.TEST2
          OPEN 'VOC' TO F.FILE ELSE STOP "CANNOT OPEN VOC"
          READU REC FROM F.FILE,'LIST'
          LOCKED
             USERNO = STATUS()
             CRT "USER HOLDING LOCK IS ":USERNO
             RET = USERINFO(2,USERNO,USERINFO)
             PID = USERINFO<1,3>
             CRT "PID IS ":PID
             EXECUTE "LISTUSER PID ":PID
          END ELSE STOP 'CANNOT READ LIST'
       END
    >RUN BP LOCK.TEST2
    USER HOLDING LOCK IS -1
    PID IS 16318604
    UsrNo Pid...... UID.. UserName Type Acct.............. LogonTime...............
       -1  16318604     0 root     Phan /disk1/morrisn     Tue May 21 07:49:56 2024

    Search lines returned: 1 (of 2)

    Hope this helps.

    Thanks,

    Neil



    ------------------------------
    Neil Morris
    Universe Advanced Technical Support
    Rocket Software
    ------------------------------
    Héctor Cortiguera
    Participating Frequently
    May 22, 2024 6:43 AM UTC

    Hi Hector,

    I'm not sure if the following meets your requirements, but if you do a READU using the LOCKED clause, the STATUS() returns the user holding the lock. And the USERINFO() function and LISTUSER command can be used to return additional information.

    >COPYP BP LOCK.TEST2 (TSN

         LOCK.TEST2
          OPEN 'VOC' TO F.FILE ELSE STOP "CANNOT OPEN VOC"
          READU REC FROM F.FILE,'LIST'
          LOCKED
             USERNO = STATUS()
             CRT "USER HOLDING LOCK IS ":USERNO
             RET = USERINFO(2,USERNO,USERINFO)
             PID = USERINFO<1,3>
             CRT "PID IS ":PID
             EXECUTE "LISTUSER PID ":PID
          END ELSE STOP 'CANNOT READ LIST'
       END
    >RUN BP LOCK.TEST2
    USER HOLDING LOCK IS -1
    PID IS 16318604
    UsrNo Pid...... UID.. UserName Type Acct.............. LogonTime...............
       -1  16318604     0 root     Phan /disk1/morrisn     Tue May 21 07:49:56 2024

    Search lines returned: 1 (of 2)

    Hope this helps.

    Thanks,

    Neil



    ------------------------------
    Neil Morris
    Universe Advanced Technical Support
    Rocket Software
    ------------------------------

    Hi Manu and Neil

    Thanks, that was just what I needed. 



    ------------------------------
    Héctor Cortiguera
    Quiter Servicios Informaticos SL
    ------------------------------
    MARY E SCHULZ
    Rocketeer
    May 22, 2024 6:32 PM UTC

    Hi Hector,

    I'm not sure if the following meets your requirements, but if you do a READU using the LOCKED clause, the STATUS() returns the user holding the lock. And the USERINFO() function and LISTUSER command can be used to return additional information.

    >COPYP BP LOCK.TEST2 (TSN

         LOCK.TEST2
          OPEN 'VOC' TO F.FILE ELSE STOP "CANNOT OPEN VOC"
          READU REC FROM F.FILE,'LIST'
          LOCKED
             USERNO = STATUS()
             CRT "USER HOLDING LOCK IS ":USERNO
             RET = USERINFO(2,USERNO,USERINFO)
             PID = USERINFO<1,3>
             CRT "PID IS ":PID
             EXECUTE "LISTUSER PID ":PID
          END ELSE STOP 'CANNOT READ LIST'
       END
    >RUN BP LOCK.TEST2
    USER HOLDING LOCK IS -1
    PID IS 16318604
    UsrNo Pid...... UID.. UserName Type Acct.............. LogonTime...............
       -1  16318604     0 root     Phan /disk1/morrisn     Tue May 21 07:49:56 2024

    Search lines returned: 1 (of 2)

    Hope this helps.

    Thanks,

    Neil



    ------------------------------
    Neil Morris
    Universe Advanced Technical Support
    Rocket Software
    ------------------------------

    Hi Hector and Manu, 
    MultiValue Experience: Performance (MVX) would be very helpful in identifying users who lock files.  With MVX there is a nice web-based UI (see screen shots below) and you, or anyone you select, can get email notifications of the issues.  With thresholds within MVX, you can even set the triggers for email notifications and events.  If you'd like a demo of MVX, please feel free to reach out to me: mschulz@rocketsoftware.com




    ------------------------------
    MARY E SCHULZ
    Sr. Product Manager, MultiValue Experiences
    Rocket Software
    mschulz@rocketsoftware.com
    ------------------------------