Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can several instances of exec share same log file ?

Status
Not open for further replies.

dans45

Technical User
Feb 13, 2003
43
US
Hello, I've got a file that I start with a batch file in several W2K widows using the line:
start cmd /c "c:\myfile.exe" 0
start cmd /c "c:\myfile.exe" 1
...
I'm opening up five instances currently. Each instance shares the same log file. The exec file has the shared log file open from start to finish.
filehandle = fopen(logfn, "a+t")
So far it appears to work. Is this by luck or should I create separate log files from each instance and merge them after each instance completes? I'm using visual C++.net. The exec is just a console file however.
Thanks for your help.
 
Since you're using C++, you might want to post in one of the C++ forums in the future.

If multiple instances of your program are running at the same time, you should definitely do something to prevent them from writing to the file at the same time, otherwise the log file might get corrupted with half a log entry from one program, then half from another...

Your idea of using separate log files and then merging them is good. You could also use a separate file as a flag.
Ex. When a program wants to write to the log file, it checks if the flag file exists, if it does then wait, if not then create it and write to the file, then delete the flag file when you're done writing to the log file.
 
Thanks cpjust for the info. I submitted here because the progam is c although I used a c++ compiler. I agree with your comment. In some cases all instances post all results and in others they don't.
 
hi dans45 ,
in my opinion you should use IPC calls to synchronise the shared file operation between multiple instances.

cheers
sanjay
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top