McLean IT Consulting

WORRY FREE IT SUPPORT

Call Us: 250-412-5050
  • About
  • Services
    • IT Infrastructure Design
    • Remote & Onsite IT Support
    • Disaster Recovery
    • IT System Monitoring
    • IT Audit
    • Documentation
    • Medical IT Solutions
    • Wireless Networks
    • Cloud Computing
    • Virtualization
  • Partners
    • Lenovo
    • Ubiquiti Networks
    • Dragon Medical Practice Edition (Nuance)
    • Synology
    • Drobo
    • Adobe
    • Bitdefender
    • NAKIVO
  • Contact
  • Blog
  • Remote Support

Synology – See Files Locked by SMB Users

April 18, 2016 By Andrew McLean 5 Comments

Synology DS1815+

I’m amazed this never came up for me before, but I recently had to diagnose a weird issue where we were seeing shared files locked, preventing other users from accessing them. Thankfully it turned out to be unrelated to the Synology, but I did discover a useful command in the process.

As usual, these advanced commands require that you SSH into the command line interface of the Synology box. You may login as root if using DSM 5.2, or as an admin user/sudo if using DSM 6.0. For the purposes of this blog post I’ll assume DSM 6.0.

So first you remote into the box:
[code lang=”bash”]ssh admin@[synology_IP][/code]

Then run the command “smbstatus” as root via sudo:
[code lang=”bash”]sudo smbstatus[/code]

You’ll be prompted for a password, then it’ll display the output.

First you’ll see a list of client sessions, followed by a list of locked files, similar to the screenshot below.

output of smbstatus
smbstatus output clearly showing files locked

Now the output itself has a few parts as identified by the header. The PID is the process controlling the session or locking the file. The UID is the user that this process is running as. The numbers aren’t very descriptive, but you can reverse search those numbers to get relevant information.

To get the Process Name from UID:
[code lang=”bash”]ps -p 11315-o comm=[/code]

PS is one of the most basic commands in Linux operating systems. In this case we’re using PS to query the PID (as specified by -p [UID]) and then telling it what output format we want (using -o) – in this case “comm” which is the name of the command. Clear as mud? Good. In this example it reveals nothing interesting because we already know the process that has locked these files is the SMB process. The output shows smbd

We can also assume that the UID is the user that is currently accessing or locking the file, but especially in a busy network, it can be useful to identify precisely which user is accessing and/or locking a file. And for this we use a slightly more clunky command to reverse-search the UID.

[code lang=”bash”]awk -v val=1027 -F ":" ‘$3==val{print $1}’ /etc/passwd[/code]

Now AWK is a pattern-matching tool that I couldn’t even begin to explain in this post, but suffice it to say the rest of the command is there to feed it a pattern to match (in this example 1027), find the matching UID row and output the third column value (that is, the name) of the user, all of which is found in the file /etc/passwd. Or put in simpler terms, it looks inside /etc/passwd for the username matching the UID.

Filed Under: Tips

Comments

  1. Dan says

    October 9, 2017 at 8:31 am

    I am seeing this issue for one of our clients using a diskstation. I’m also not convinced it is the diskstation itself causing this. What was the actual issue in your case?

    Log in to Reply
    • Andrew McLean says

      October 25, 2017 at 2:21 am

      I apologize, this was long enough ago that I don’t exactly remember. Reviewing my notes from the time also don’t indicate what the underlying cause was.
      I feel a bit stupid now, not including information like that. I just remember ruling out the Synology as the problem, since that was the product I was supporting at the time.

      Log in to Reply
      • Talha says

        July 29, 2019 at 12:30 am

        How to unlock the locked files ?

        Log in to Reply
  2. Ryan Kassel says

    December 13, 2017 at 9:28 am

    Make sure and close the preview pane!

    Log in to Reply
  3. Marius says

    September 28, 2021 at 1:13 pm

    Hmmm

    Im getting

    awk: cmd. line:1: ‘==val{print
    awk: cmd. line:1: ^ invalid char ” in expression

    Any ideea?

    Log in to Reply

Leave a Reply Cancel reply

You must be logged in to post a comment.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Contact Us

McLean IT Consulting Inc.
Serving Greater Victoria

P: 250-412-5050
E: info@mcleanit.ca
C: 250-514-2639

Featured Article

Document It, or It Doesn’t Exist

Not to beat a dead horse, but I wanted to be clear on the importance of IT documentation. To date, I've yet to start with a client who already has it. … Continue Reading

Blog Categories

Our Mission

We seek to enrich and improve small and medium businesses by delivering best-in-class technology solutions, and offering a premier customer service experience. Contact Us Now!

Quick Menu

  • About
  • Testimonials
  • Contact
  • Blog
  • Sitemap

Let’s Get Social

  • Email
  • Facebook
  • LinkedIn
  • Twitter
  • YouTube

Copyright © 2025