13_03__shmWriteZ
ZC: Unix网络编程第2版 第2卷 第13章
1、mainWriteZ.cpp
#include <unistd.h> #include <stdio.h> #include <stdlib.h> #include <errno.h> #include <sys/mman.h> #include <sys/stat.h> #include <fcntl.h> #define FILE_MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) int main(int _argc, char** _argv) { printf("*** shmWrite *** Z ***\n"); int i,fd; struct stat stat01; unsigned char *ptr; if (_argc != 2) { printf("usage : shmwrite <name>\n"); exit(0); } fd = shm_open(_argv[1], O_RDWR, FILE_MODE); fstat(fd, &stat01); ptr = (unsigned char *)mmap(NULL, stat01.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); close(fd); for (i=0; i<stat01.st_size; i++) *ptr ++ = i % 256; exit(0); return 0; }
2、mainWriteZ.pro
TEMPLATE = app CONFIG += console CONFIG -= app_bundle CONFIG -= qt SOURCES += \ mainWriteZ.cpp LIBS += -lrt include(deployment.pri) qtcAddDeployment()
3、

浙公网安备 33010602011771号