A file refuses to be renamed or the share “is in use” and nobody admits to anything. Before I restart Samba on a busy server, I’d want to know who is still working in it. smbstatus answers that and it ships with Samba.
smbstatus -L
The manual says -L makes smbstatus list only the locks, which is the list of files that clients hold open. Run it on the server itself. The tool reports on current Samba connections, and a few options narrow the output down:
-Slists only the shares that clients are connected to.-bgives brief output.-u nameshows only the information for one user.-pprints thesmbdprocesses and exits, which the manual calls useful for scripting.-jprints more detailed output as JSON instead of text a human reads.
Use the JSON form if you want to feed the result to another tool, for example smbstatus -L -j.
One caveat: -f skips the check whether the processes in the status data still exist. That is faster on busy systems, but the manual warns it can show stale data for processes that died without cleaning up. Leave it off when you are deciding whether it is safe to restart something. Add -B if you also want byte-range locks in the list.
Further reading: smbstatus man page
Going deeper: Guide: your Unraid cache is full and Docker stopped, how to find out why and fix it