LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-29-2005, 09:19 AM   #1
prell
Member
 
Registered: Jul 2004
Posts: 73

Rep: Reputation: 15
Getting PIDs which have files open / waiting for file write to complete


I have a program that waits for new files in a directory. As soon as a new file is created, my program begins reading and processing it. Apparently, this reading can occur even as the file is being written, and may end before the write process is completed. Ideally, what I'd like to do is wait until the write is complete. I've tried opening the file for write access, which I assumed would wait until the other writing process closed the file, but that doesn't seem to be the case. Can this be done? Or, is there an easy way to figure out if someone (a process) has a file open for write access?
 
Old 03-29-2005, 09:25 AM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
Do you control the process that's writing the files? If so, you may be able to use fcntl(). You didn't mention what language your program is written in, but this is for C/C++. You'd use it with this flag:
Code:
       F_SETLK
              The lock is set (when l_type is F_RDLCK or F_WRLCK)
              or cleared (when it is F_UNLCK).  If  the  lock  is
              held by someone else, this call returns -1 and sets
              errno to EACCES or EAGAIN.
 
Old 03-29-2005, 09:39 AM   #3
prell
Member
 
Registered: Jul 2004
Posts: 73

Original Poster
Rep: Reputation: 15
Oh yeah whoops, I'm sorry: I do not have control over the program(s) writing the files. However, it will be samba or scp or just cp, usually. My code is in C++.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
grip : no write access to write encoded file bidouilleur Linux - Software 5 10-09-2010 09:23 PM
Hard Drive Problems: timeout waiting for DMA; error waiting for DMA mintee Linux - Hardware 10 09-21-2007 05:06 AM
G++ environment variables, rerouting output, file listings and PIDs Kawahee Programming 7 09-19-2005 12:40 PM
core files appending PIDS - they shouldn't be! LavieX Linux - Enterprise 2 04-15-2005 02:26 PM
I cannot make rox open a +x file as normal files codec Linux - Software 1 05-02-2004 06:04 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:28 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration