locked
System process (PID=4) locks file RRS feed

  • Question

  • Hi

    I have the following situation:

    A couple of processes (out application) work on the same folder reading files.
    Each process tries to lock a file exclusive before it starts to work with it. If the file cant be locked exclusive its not treated.
    If its done the lock is released and the file is deleted.
    A FileWatcher in each process creates events files modified or deleted.
    Everything works fine so far.But testing now special situations:
    A process has the file locked exclusive. I suspend the process (so the other ones can handle all files in the folder) and then stop it.
    I would expect that the exclusive lock is released by os and another process would handle the file.

    What actually happens:
    The file is now locked by System process (PID=4). No event takes place and the file is not handled anymore.
    A release of the lock can be achieved by copy/past the file!

    I found some links like:
    https://connect.microsoft.com/VisualStudio/feedback/details/586436/system-locks-exe-on-build
    which locates the problem in a virus scanner or a release of the lock after a certain time. But this is not the case here.

    What is the meaning of having the lock transferred to System (PID=4)?
    Can I avoid a behavior like this and get a regular modify-event?

    Thanks for feedback

    Beat

    Tuesday, July 3, 2012 5:11 PM

Answers

  • If an application does.... exit. Correct?>> No in this situation there is no owner of lock but resource will still be locked till it got reset , there are two types of locks AutoReset/Manual Reset so it depends what type of locking is used by Program. (Your Case of copying a file is of IO that is handled by OS , application does nothing)

    I cant avoid having ..... Correct?>> System is not taking locks actually it is applying IO lock on the resource that you application is trying to modify , in-fact application has no idea of it because IO operation are taken care by dedicated IO threads solely managed by OS

    So in nut shell you can not avoid OS taking lock of file while modifying it.

    • Marked as answer by BeatHoe Monday, July 16, 2012 6:28 AM
    Friday, July 13, 2012 4:48 PM

All replies

  • As for as i know , suspending the process do not release IO locks 

    so is any file is being modified/Read by a process then it means lock has been placed and I/O thread has started reading data , so even if you suspend the process I/O thread will keep running and waiting for caller response (Call back) to process the data that has been read. But in your case caller process is suspended so it turn infinite wait and lock never get releases.

    Same would be the case if process is terminated forcefully , that usually leave LOCKs unreleased till timeout

    Also you will not see any modified event because process is at halt and not process I/O operation , Modified event is fired when I/O operation commits the operation and file attribute changes 

    For me it looks normal situation and in real time it won`t be much problem because OS never suspend a process for very long

    Ashwini  

    Wednesday, July 4, 2012 3:03 PM
  • Thanks for the info.

    I agree for suspended processes to hold locks.
    I agree also for not getting a modify event when I kill it.

    But its not possible to handle the situation (in a programmatic way) when the system process (pid=4) takes the lock.

    To my current knowledge its only possible to release the lock with a manually done copy/paste.
    Maybe somebody knows another way how to release the lock?

    Regards

    Beat

    Friday, July 6, 2012 8:56 AM
  • Ya may be but one thing.

    Are you say that even if file is locked you can do a coy (CTRL+C) and (CRTL+V) is forcing the lock release?

     
    Friday, July 6, 2012 12:33 PM
  • Yep.

    When I kill one my processes it happens to leave a file locked.
    The other processes don't touch it, since it is locked. I cant delete it manually since it is locked.
    Verify with ProcessExplorer the locking process => System (PID=4).
    Then do a copy/paste in a explorer and the lock is gone.
    Now one of my processes handles both files (the original and the copy).

    Beat

    Friday, July 6, 2012 4:07 PM
  • Yes that is expected , 

    when your process issue a write/read IO operation it lock the resource , but when you copy /paste the same process (system) tried to take a read lock file while asking read lock lock itself get releases because no one has reference of (in same process)

    what i would say this scenario is very very unlikely and suggested is Won`t FIX 

    Ashwini 

    Monday, July 9, 2012 2:35 PM
  • Thanks for the answer. This is clear now.

    I'm still puzzled with the System (PID=4) process. 2 more questions:

    If an application does not release locks (because of application programming errors) the system process takes the locks on application exit. Correct?

    I cant avoid having the system process taking locks when an application processes is killed holding a lock. Correct?

    All these locks are released within a timeout?

    Thanks for feedback

    Thursday, July 12, 2012 9:15 AM
  • If an application does.... exit. Correct?>> No in this situation there is no owner of lock but resource will still be locked till it got reset , there are two types of locks AutoReset/Manual Reset so it depends what type of locking is used by Program. (Your Case of copying a file is of IO that is handled by OS , application does nothing)

    I cant avoid having ..... Correct?>> System is not taking locks actually it is applying IO lock on the resource that you application is trying to modify , in-fact application has no idea of it because IO operation are taken care by dedicated IO threads solely managed by OS

    So in nut shell you can not avoid OS taking lock of file while modifying it.

    • Marked as answer by BeatHoe Monday, July 16, 2012 6:28 AM
    Friday, July 13, 2012 4:48 PM
  • Common Windows 7 problem, Best soution: - Download Microsoft Process explorer and kill system PID 4 !!!
    Thursday, October 16, 2014 12:20 PM
  • Huh, I never had this problem in Windows 7, Windows 10 has it a lot, really annoying : ((

    Hope Microsoft can make a fix for this huge BUG, I mean process explorer say the file handle is invalid, then System (PID=4) please clean this handle up so I can move this directory without rebooting first........ ; ))

    Tuesday, May 1, 2018 8:45 AM
  • Lol after just having said this, I seem to have find a workaround????? if I copy the directory first, then delete, all problems are gone?????????????????????????????
    Tuesday, May 1, 2018 10:58 AM
  • I solve the problem changing the option "Copy Local" to true for the system reference, with this, the system.dll is copied to the debug directory every time that you start the project preventing that the system.dll of windows lock the process because every run is renewed the system.dll
    Wednesday, July 4, 2018 4:42 AM