How to delete a locked file ?

G

Ganesh

Hi,

I would like to know if there is any way I can forcefully delete a
file locked by another process on Windows as well as on Linux.

On windows DeleteFile returns me error code 32 (Process cannot access
the file because it is being used by another process)

Thanks in advance.

Regards,
Ganesh
 
G

Gavin Deane

Hi,

I would like to know if there is any way I can forcefully delete a
file locked by another process on Windows as well as on Linux.

On windows DeleteFile returns me error code 32 (Process cannot access
the file because it is being used by another process)

There's no standard C++ answer to your question. If it is possible to
do what you want, the answer will be specific to each platform, so
you'll need to ask platform-specific groups. Some suggestions from the
FAQ

http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.9

Gavin Deane
 
L

Lionel B

Hi,

I would like to know if there is any way I can forcefully delete a file
locked by another process on Windows as well as on Linux.

On windows DeleteFile returns me error code 32 (Process cannot access
the file because it is being used by another process)

This has nothing to do with the C++ language, which is what this ng deals
with; you'd be better off trying a Windows newsgroup (BTW, as far as I
know Linux does not "lock" files).
 
G

Gianni Mariani

Lionel said:
This has nothing to do with the C++ language, which is what this ng deals
with; you'd be better off trying a Windows newsgroup (BTW, as far as I
know Linux does not "lock" files).

Linux does have file locks, but it does not prevent you from deleting them !

BTW - I found a very strange behaviour on XP when attempting to delete a
file. If I had issued a delete system call on an open file, it would
not appear deleted until after the file was closed - spooky.

As far as I know (which is not much), windows does not support deleting
a file that is even open, let alone locked (apart from this spooky
delete the file later thing that goes on).
 
L

Lionel B

Linux does have file locks, but it does not prevent you from deleting
them !

Ah, yes; Linux file locks are apparently "advisory" and may thus be
ignored "given suitable permissions" on the file in question (whatever
that means).
 
?

=?iso-8859-1?q?Erik_Wikstr=F6m?=

Ah, yes; Linux file locks are apparently "advisory" and may thus be
ignored "given suitable permissions" on the file in question (whatever
that means).

It means that in true Unix spirit root can always do whatever he/she/
it wants, even if other users are reading from the file :)
 
J

James Kanze

Ah, yes; Linux file locks are apparently "advisory" and may thus be
ignored "given suitable permissions" on the file in question (whatever
that means).

Advisory means that a lock doesn't prevent anyone from doing
anything. They advise, they don't constrain.

Whether this is a good thing generally is debatable, but the
administrator must at least be able to override a lock (or
anything else).
 
J

James Kanze

It means that in true Unix spirit root can always do whatever he/she/
it wants, even if other users are reading from the file :)

It means more than that. Obviously, root must be able to do
anything, regardless of what other users are doing, if only to
allow exit from DoS attacks. "Advisory", however, means that
any protection depends on collaboration. A lock in one process
doesn't prevent access in any way by another process. If the
other process is collaborating, however, it will also ask for a
lock, and be informed that it can't get one (or be suspended
until it can).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top