How do you check if a file is already opened in C?

Bảo Vy

Member
How do you check if a file is already opened in C?
Answer
If you tend to do it in shell, you can simply use
lsof $filename. You can use int flock(int fd, int operation); to mark a file as locked and also to check if it is locked. Apply or remove an advisory lock on the open file specified by fd. The argument operation is one of the following: LOCK_SH Place a shared lock.
 

Tìm kiếm

Back
Top