Force a Samba process to close a file


Is there a way to force a Samba process to close a given file without killing it?

Samba opens a process for each client connection, and sometimes I see it holds open files far longer than needed. Usually i just kill the process, and the (windows) client will reopen it the next time it access the share; but sometimes it's actively reading other file for a long time, and i'd like to just 'kill' one file, and not the whole connection.

edit: I've tried the 'net rpc file close ', but doesn't seem to work. Anybody knows why?

edit: this is the best mention i've found of something similar. It seems to be a problem on the win32 client, something that microsoft servers have a workaround for; but Samba doesn't. I wish the net rpc file close <fileid> command worked, I'll keep trying to find out why. I'm accepting LuckyLindy's answer, even if it didn't solve the problem, because it's the only useful procedure in this case.

Best Answer

This happens all the time on our systems, particularly when connecting to Samba from a Win98 machine. We follow these steps to solve it (which are probably similar to yours):

  • See which computer is using the file (i.e. lsof|grep -i <file_name>)
  • Try to open that file from the offending computer, or see if a process is hiding in task manager that we can close
  • If no luck, have the user exit any important network programs
  • Kill the user's Samba process from linux (i.e. kill -9 <pid>)

I wish there was a better way!

Related Topic