How to prevent a C++ program reading a file that is still being written to.?


 
Thread Tools Search this Thread
Top Forums Programming How to prevent a C++ program reading a file that is still being written to.?
# 8  
Old 06-26-2014
The only way to know the file has been completely written is to have the writing process signal success in some way. Because only the writing process knows if it has successfully written all the data supposed to be in the file. The receiving process can not infer that accurately because of failure conditions, so any method based on timestamps or something similar can not be guaranteed to work.

Period.

Renaming the file is probably the best way to do that.

There are some kludges you can use on Solaris using the utssys() call that will return the process IDs of process that have any file open, but that will just tell you the file is open and won't tell you why the process has the file open, nor why it closed it. Look at the "sys/utssys.h" header file.

If you can find the source code for the Solaris "fuser" utility, you can see an example of how to use it.

Or you can run the "fuser" utility in a subprocess using system() or popen().
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Debugging a program written in two languages

Subject: Debugging a program written in two languages Platform: Linux (Kubuntu) I am trying to debug a C application with bindings to some simple functions written in Ada using the GNAT Programming Studio IDE (GPS). The main entry point is in C. The debugger is gdb. I managed to compile... (0 Replies)
Discussion started by: NiGHTS
0 Replies

2. Programming

Reading long options in C++ program

I am reading arguments passed to a C++ program which accepts long options. Long options start with '--', with the value joined with the option by an = sign, with no intervening spaces. An example is as follows: programName --vdz=15.0 I want to store 'vdz' in variable 'key', whereas... (4 Replies)
Discussion started by: kristinu
4 Replies

3. Shell Programming and Scripting

Reading from a file a background program writes to

Hi! #!/usr/bin/env bash rm tmpcomm nc -v -u -l 444 | hexdump -b > tmpcomm while : do read l1 < tmpcomm read l2 < tmpcomm read l3 < tmpcomm read l4 < tmpcomm # do something doneI start netcat in the background and listen for an incoming conncetion. All incoming... (1 Reply)
Discussion started by: torax123
1 Replies

4. Programming

Reading ELF file Symbol table of C++ program

Folks, I have some program(Test.cpp) as follows, #include<iostream> class Abc { private: int _theVar; public : int printVar(); }; int Abc :: printVar() { _theVar=10; } main() { Abc _t; (2 Replies)
Discussion started by: vinod_chitrali
2 Replies

5. Linux

Reading ELF file Symbol table of C++ program

Folks, I have some program(Test.cpp) as follows, #include<iostream> class Abc { private: int _theVar; public : int printVar(); }; int Abc :: printVar() { _theVar=10; } main() { Abc _t; (0 Replies)
Discussion started by: vinod_chitrali
0 Replies

6. Shell Programming and Scripting

prevent errors/warnings from being written to log file

i have this script which works fine but shows errors when it runs..these are more like warnings and the script runs fine.. i am on a sun machine.. i know it writes all the error messages to a master log file.. is there any way i can turn off these warnings/error messages and prevent them from being... (2 Replies)
Discussion started by: npatwardhan
2 Replies

7. Shell Programming and Scripting

How to prevent the pattern "^[[0m" from being written to a file ????

Hi folks, I am using a shell script to display the referred libraries names of any specified cpp code. Given below is the script: shell script "grblib" ------------------------------------------------------------------------- #!/bin/sh # get the lines having "include" pattern ... (5 Replies)
Discussion started by: frozensmilz
5 Replies

8. Programming

How to clear the content of a pipe (STDIN) after it is written to another program?

PROGRAM A <-> PROGRAM B PROGRAM A sends data as STDIN ro PROGRAM B and when PROGRAM B is executed from PROGRAM A, it sends output back to PROGRAM A. This is implemented using 2 pipes (fd1 & fd2). The above process happens in a loop and during the second run, the previous data that had been... (10 Replies)
Discussion started by: vvaidyan
10 Replies

9. UNIX for Dummies Questions & Answers

reading filenames inside a program

UNIX Sun Ultra60 5.5.1 Hello everybody, I have a problem that seems simple but turns out to be complex (for me at least). My program needs to open a directory (this part is easy), scan each filename and determine whether or not a file with the suffix (.07) exists. So the program would return... (5 Replies)
Discussion started by: j_t_kim
5 Replies

10. UNIX for Dummies Questions & Answers

File being used/written

Hello, Which command in unix can tell whether a file is being used/written by another process. e.g. If one process is copying a very big file in some directory and there is another cronjob process which checks for a new file and in this directory and process the file. I want to check, if the... (4 Replies)
Discussion started by: sanjay92
4 Replies
Login or Register to Ask a Question
SMPPPD-C.CONF(5)						      SMPPPD							  SMPPPD-C.CONF(5)

NAME
smpppd-c.conf - configuration file for smpppd frontends DESCRIPTION
When frontends of smpppd like cinternet , qinternet or kinternet want to connect the smpppd they may read the file /etc/smpppd-c.conf. The configuration file /etc/smpppd-c.conf has a simple file format with a key = value pair in each line. OPTIONS
sites = <list of sites> Tell the frontends where to find the smpppd. Frontends will try to connect to the smpppd in the order defined here. Possible sites are: local Connect to locally running smpppd (via socket in the local namespace). gateway Connect to smpppd running on the gateway. config-file Connect to smpppd as specified in this file. slp Connect to smpppd as retrived from the slp daemon (service location protocol). server = <server> Specifies the host on which the smpppd is running. port = <port> Specifies the port number of the smpppd. password = <password> The password to use for authentication at the smpppd, UTF-8 encoded for those who really care. SEE ALSO
kinternet, qinternet, cinternet(1), smpppd(8). AUTHOR
Arvin Schnell <arvin@suse.de> SuSE January 2004 SMPPPD-C.CONF(5)