Sponsored Content
Top Forums Programming what is the main difference between difference between using nonatomic lseek and O_APPEND Post 302715083 by jim mcnamara on Saturday 13th of October 2012 06:36:52 PM
Old 10-13-2012
O_APPEND guarantees that every write to the file will be at the end of the file. lseek guarantees that the file pointer is positioned to the current EOF of the file. It does not guarantee that subsequent writes will be at the end of the file.

The above is something that you only worry about when multiple processes or threads are writing to one file.

Neither guarantees any kind of sequence of I/O writes when there are multiple writers. If you need that, then you have to resort to something like SYSV semaphores for multi-process apps or mutxes in the case of multi-threaded apps.
This User Gave Thanks to jim mcnamara For This Post:
 

10 More Discussions You Might Find Interesting

1. Linux

what is the difference between -h and -H ?

samba:/home/backup # df -h /home/ Filesystem Size Used Avail Use% Mounted on /dev/sdb2 34G 8.6G 26G 26% /home samba:/home/backup # df -H /home/ Filesystem Size Used Avail Use% Mounted on /dev/sdb2 37GB 9.2GB 28GB 26% /home what... (2 Replies)
Discussion started by: cw1972
2 Replies

2. UNIX for Dummies Questions & Answers

What is the main difference between grep and sed

What is the main difference between grep and sed (1 Reply)
Discussion started by: ss4u
1 Replies

3. UNIX for Dummies Questions & Answers

What's the Difference Between / and //?

Many times over the years, I've noticed that if I accidentally type 'cd //', my bash prompt will display that I am in // instead of /. If I do an ls command, it looks just like I'm in /. So this morning I decided to try and do 'cd ///' all the way up to a full 'cd //////'. None of those attempts... (1 Reply)
Discussion started by: deckard
1 Replies

4. Shell Programming and Scripting

difference?

Hi what is the difference between following: if then //some code fi AND if test then //some code fi (3 Replies)
Discussion started by: skyineyes
3 Replies

5. Shell Programming and Scripting

difference between > and >>

please explain in detail (2 Replies)
Discussion started by: crackthehit007
2 Replies

6. Shell Programming and Scripting

Difference between 1,$ and /g

just wondering what the difference is between 1,$ and /g when doing a substitution in vi. doesn't seem to be much difference from what i can see. (2 Replies)
Discussion started by: bigubosu
2 Replies

7. UNIX for Dummies Questions & Answers

the difference is?

scp 123.txt user1@computer1.com:..//john_x1/lab scp 123.txt user1@computer1.com:../john_x1/lab What is the difference between single and slash here and in general? How to copy if we have a unique directory somewhere? Is some of above ways more prefered or... better solutions exists??? ... (8 Replies)
Discussion started by: c_lady
8 Replies

8. UNIX for Dummies Questions & Answers

Difference between

$x=10 and providing the spaces between = and 10 $x= 10 (4 Replies)
Discussion started by: shashank1311
4 Replies

9. Shell Programming and Scripting

What is the difference between the two?

Heyas I'm reworking tui-dd atm, and having a similar issue with a 'weird formated tempfile'. I've already applied what seemed to help from: https://www.unix.com/unix-for-dummies-questions-and-answers/261156-awk-should-work-shouldnt-2.html However, it is weird... The mini-dd works as... (2 Replies)
Discussion started by: sea
2 Replies

10. Shell Programming and Scripting

awk to calculate difference of split and sum the difference

In the awk I am trying to subtract the difference $3-$2 of each matching $4 before the first _ (underscore) and print that value in $13. I think the awk will do that, but added comments. What I am not sure off is how to add a line or lines that will add sum each matching $13 value and put it in... (2 Replies)
Discussion started by: cmccabe
2 Replies
PREAD(2)						     Linux Programmer's Manual							  PREAD(2)

NAME
pread, pwrite - read from or write to a file descriptor at a given offset SYNOPSIS
#include <unistd.h> ssize_t pread(int fd, void *buf, size_t count, off_t offset); ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset); Feature Test Macro Requirements for glibc (see feature_test_macros(7)): pread(), pwrite(): _XOPEN_SOURCE >= 500 || /* Since glibc 2.12: */ _POSIX_C_SOURCE >= 200809L DESCRIPTION
pread() reads up to count bytes from file descriptor fd at offset offset (from the start of the file) into the buffer starting at buf. The file offset is not changed. pwrite() writes up to count bytes from the buffer starting at buf to the file descriptor fd at offset offset. The file offset is not changed. The file referenced by fd must be capable of seeking. RETURN VALUE
On success, pread() returns the number of bytes read (a return of zero indicates end of file) and pwrite() returns the number of bytes written. Note that is not an error for a successful call to transfer fewer bytes than requested (see read(2) and write(2)). On error, -1 is returned and errno is set to indicate the cause of the error. ERRORS
pread() can fail and set errno to any error specified for read(2) or lseek(2). pwrite() can fail and set errno to any error specified for write(2) or lseek(2). VERSIONS
The pread() and pwrite() system calls were added to Linux in version 2.1.60; the entries in the i386 system call table were added in 2.1.69. C library support (including emulation using lseek(2) on older kernels without the system calls) was added in glibc 2.1. CONFORMING TO
POSIX.1-2001, POSIX.1-2008. NOTES
The pread() and pwrite() system calls are especially useful in multithreaded applications. They allow multiple threads to perform I/O on the same file descriptor without being affected by changes to the file offset by other threads. C library/kernel differences On Linux, the underlying system calls were renamed in kernel 2.6: pread() became pread64(), and pwrite() became pwrite64(). The system call numbers remained the same. The glibc pread() and pwrite() wrapper functions transparently deal with the change. On some 32-bit architectures, the calling signature for these system calls differ, for the reasons described in syscall(2). BUGS
POSIX requires that opening a file with the O_APPEND flag should have no effect on the location at which pwrite() writes data. However, on Linux, if a file is opened with O_APPEND, pwrite() appends data to the end of the file, regardless of the value of offset. SEE ALSO
lseek(2), read(2), readv(2), write(2) COLOPHON
This page is part of release 4.15 of the Linux man-pages project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at https://www.kernel.org/doc/man-pages/. Linux 2017-09-15 PREAD(2)
All times are GMT -4. The time now is 10:18 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy