ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
If the return value from write() is not -1, then the following applies.
If the return value is equal to the number of bytes you wished to write, then there is obviously no problem presented here.
If it is fewer than the number of bytes you wished to write, then the reason has nothing to do with whether a physical write has actually occurred. It happens because you've run out of space to write data to that file, and the returned number shows how many bytes you successfully wrote. An example is zero, which means the space was full before you even started to write.
Let me expand on that: this refers only to synchronous writes. If you're writing asynchronously, then you might get fewer bytes written. In that case, you need to loop back until all of them have been written.
I am try to do the followings,
1) I have an app that receives data from TCP socket and writes to a file for bufferring. Data in this file is then processed by several computational processes to extract information. (i.e. One-Write-Many-Read).
The file organization is records of 2-byte-length-descriptor + the actual binary data. There will be 350MB in this file per day. The first app uses writev(2). The computational processes uses read(2) starting off reading the 2-byte len, and then read again in a loop for the rest of the binary data.
2) These extracted information are then written to a centralized log file, and this log file will be read by another process so that appropriate information will be delivered to various clients over TCP sockets. (i.e. Many-Write-Many-Read).
The file organization is variable-length records separated by newline character, so that fputs() and fgets() can be easily used, and this log can be `cat` for examination.
I do use file for inter-process communication a lot. I worry about write or writev not finishing a complete record and then another write kicks in. Any advice please. Thanks.
----
Hi Wje,
I do only synchronous write to ensure records written to file are permanent. If the target runs out of space, the problem is more than just an incomplete record. I can deal with that later. Thanks.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.