01-26-2004
mmap & msync
I really can't understand why this programm doesn't work (on linux); it open mapped memory, changes one byte and write back to disk:
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
int main() {
int fd, err;
void * mm;
fd = open("math.dat", O_RDWR);
mm = (char*)mmap(0, 10, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
if ((int)mm == -1) perror("mmap");
sprintf((char*) mm, "%d\n", 100);
close(fd);
err = msync(mm, 10, MS_ASYNC);
if (err == -1) perror("msync");
err = munmap(mm, 10);
if (err == -1) perror("munmap");
exit(0);
}
No errors, just no modification on disk.
TIA
marquis
10 More Discussions You Might Find Interesting
1. Filesystems, Disks and Memory
Hello. I'm writing some random access i/o software on Solaris 8 using mmap64 to memory map large files (my test file is ~25 GB).
The abbreviated code fragment is:
fd = open(cbuf,O_RDONLY|O_LARGEFILE);
struct stat statbuf;
fstat(fd,&statbuf);
off_t len =... (0 Replies)
Discussion started by: gusm
0 Replies
2. UNIX for Advanced & Expert Users
I'm using select() to monitor multiple file descriptors (inet sockets) in application. But this application must also collaborate with other applications on the same host via shared memory (mmap'ed file) due to performance reasons. How can I become notification that mmaped memory is changed or... (1 Reply)
Discussion started by: Hitori
1 Replies
3. UNIX and Linux Applications
Hi guys,I'M a newbe and trying to set up msync.
I run Ubuntu on my lap top and have got a sony-ericsson w910i. All I like to do is sync calendar/contacts with evolution.
So I have installed multisync 0.82 and tried to sync my phone with evolution via bluetooth.
However it seems to get stuck at... (0 Replies)
Discussion started by: sn0m
0 Replies
4. Linux
Whne I try to execute following code then get an erro message that "Invalid Argumemt" in msync.
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/errno.h>
#include <sys/time.h>
#include <fcntl.h>
#include <stdio.h>... (0 Replies)
Discussion started by: darshan.ghumare
0 Replies
5. UNIX for Dummies Questions & Answers
how to use mmap() to map a file to memory space. Do you have any simple program???? Because I have to implement lot of concepts into it. (3 Replies)
Discussion started by: gokult
3 Replies
6. Programming
how to use mmap() to map a file to memory space. Do you have any simple program???? Because I have to implement lot of concepts into it. (5 Replies)
Discussion started by: gokult
5 Replies
7. Homework & Coursework Questions
Descriptions:
Develop a program that uses mmap() to map a file to memory space. Prepare such a file by yourself and do the follows.
<LI class=MsoNormal>Display the content of the file after mapping; <LI class=MsoNormal>Output how many digits included in the file; <LI class=MsoNormal>Replace... (1 Reply)
Discussion started by: gokult
1 Replies
8. Programming
hai,
How do we map 'n' number of files into memory by using mmap system call??
Thanks in advance...... (5 Replies)
Discussion started by: andrew.paul
5 Replies
9. UNIX for Advanced & Expert Users
Hi
I want to lock or prevent a portion of memory which I allocated. So I tried MLOCK, MPROTECT and some like this. But all these functions works only on page border. Can I know why that so.
Is that possible to protect a portion of memory which is in middle of the page.
Example.
int A;
... (1 Reply)
Discussion started by: jionnet
1 Replies
10. Emergency UNIX and Linux Support
I want to know whether this is possile or ever been tried out.
I want to obtain a chuck of memory using mmap()
I do it so :
n = mmap(0, 8000, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
And hold on to that memory, when a process requests for memory, some memory is... (2 Replies)
Discussion started by: xerox
2 Replies
LEARN ABOUT REDHAT
vwarnx
ERR(3) BSD Library Functions Manual ERR(3)
NAME
err, verr, errx, verrx, warn, vwarn, warnx, vwarnx, -- formatted error messages
SYNOPSIS
#include <err.h>
void
err(int eval, const char *fmt, ...);
void
errx(int eval, const char *fmt, ...);
void
warn(const char *fmt, ...);
void
warnx(const char *fmt, ...);
#include <stdarg.h>
void
verr(int eval, const char *fmt, va_list args);
void
verrx(int eval, const char *fmt, va_list args);
void
vwarn(const char *fmt, va_list args);
void
vwarnx(const char *fmt, va_list args);
DESCRIPTION
The err() and warn() family of functions display a formatted error message on the standard error output. In all cases, the last component of
the program name, a colon character, and a space are output. If the fmt argument is not NULL, the printf(3) -like formatted error message is
output. The output is terminated by a newline character.
The err(), verr(), warn(), and vwarn() functions append an error message obtained from strerror(3) based on a code or the global variable
errno, preceded by another colon and space unless the fmt argument is NULL.
The err(), verr(), warn(), and vwarn() functions use the global variable errno to look up the error message.
The errx() and warnx() functions do not append an error message.
The err(), verr(), errx(), and verrx() functions do not return, but exit with the value of the argument eval.
EXAMPLES
Display the current errno information string and exit:
if ((p = malloc(size)) == NULL)
err(1, NULL);
if ((fd = open(file_name, O_RDONLY, 0)) == -1)
err(1, "%s", file_name);
Display an error message and exit:
if (tm.tm_hour < START_TIME)
errx(1, "too early, wait until %s", start_time_string);
Warn of an error:
if ((fd = open(raw_device, O_RDONLY, 0)) == -1)
warnx("%s: %s: trying the block device",
raw_device, strerror(errno));
if ((fd = open(block_device, O_RDONLY, 0)) == -1)
err(1, "%s", block_device);
SEE ALSO
exit(3), printf(3), perror(3), strerror(3)
HISTORY
The err() and warn() functions first appeared in 4.4BSD.
BSD
March 6, 1999 BSD