DATA Step, Macro, Functions and more

How to know thw user that is locking a table

Reply
Frequent Contributor
Posts: 137

How to know thw user that is locking a table

Hi, I would like to know if it is possible to know in SAS which person has locked a SAS table.

 

Is it possible??

 

Thanks in advance,

Super User
Posts: 9,886

Re: How to know thw user that is locking a table

Posted in reply to juanvg1972

@juanvg1972 wrote:

Hi, I would like to know if it is possible to know in SAS which person has locked a SAS table.

 

Is it possible??

 

Thanks in advance,


I use the ps command to retrieve information about the process that has a file open. If you need to know all processes that have an active file handle on the file, use the fuser command.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Occasional Contributor
Posts: 11

Re: How to know thw user that is locking a table

[ Edited ]
Posted in reply to juanvg1972

Hi Juan,

 

     It will highly depend on your operating system. In Windows, you can use the Resource Monitor to search the "Associated Handles" this would give you the PID(s) that locks the file. You then use the task manager to find the user owning the culprit process.

 

    If UNIX/Linux, as Kurt pointed out, the fuser command will do it for you.

 

Thanks.

Frequent Contributor
Posts: 137

Re: How to know thw user that is locking a table

I am using Unix.

 

Can you give an example of fuser command?

 

Thanks

Occasional Contributor
Posts: 11

Re: How to know thw user that is locking a table

Posted in reply to juanvg1972

Pretty straightforward: fuser [filename]

 

For more information, you can run the "man fuser" command on any UNIX/Linux box or refer to the following page: http://man7.org/linux/man-pages/man1/fuser.1.html

 

Luckily for you, on a UNIX/Linux environment, you can easily automate unlocking datasets thru shell scripting.

Super User
Posts: 9,886

Re: How to know thw user that is locking a table

Posted in reply to juanvg1972

If your problem lies in updating a dataset that's opened by other users, I have created a macro that helps in this by using operating system commands to remove the file.

 

UNIX has a different layout of filesystems than Windows:

  • data space
  • allocation table (shows used and free blocks)
  • inode table (this is what Windows does not have)

Filenames in directories are just links to the inode table (in Windows the filename in the directory is a link to the allocation table); a physical file (represented by an inode that contains allocation information) can have several links pointing to the same inode. Removing such a link does not immediately remove the physical file. As long as an open file handle for the inode (not the filename!) exists, the file will keep on existing even when all links to it have been removed; only when the last file handle is closed will the inode be removed and the physical space be freed.

This allows to "remove" an open file.

My macro determines the physical filename from the library path and the dataset name, and issues a rm command. Other processes that have the file open will keep on "seeing" the old version until they close/reopen the dataset.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Valued Guide
Posts: 559

Re: How to know thw user that is locking a table

Posted in reply to juanvg1972

Base SAS don't have any functionality to know which user locked the dataset. You can know by running the operating system commands. Which operating system are you using?

Thanks,
Suryakiran
Ask a Question
Discussion stats
  • 6 replies
  • 96 views
  • 3 likes
  • 4 in conversation