xain
xain

Reputation: 13849

Open file for writing from shared lib written in C in Solaris

I need to append information into a given file from a shared lib I wrote in C in Solaris. What would be the safest way to open the file in a shared way for writing ? Being a shared lib I assume there's a risk two instances try to write to the file simultaneously.

Thanks in advance

Upvotes: 0

Views: 156

Answers (1)

Some programmer dude
Some programmer dude

Reputation: 409442

Two processes writing to the same file will, sooner or later, result in a garbled file. If you have access to both the library (which it seems you do) and the application, then you can protect all writes to the file with flock calls.

Upvotes: 1

Related Questions