Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <time.h>
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <sys/mman.h>
- #include <fcntl.h>
- int main(int argc, char *argv[]) {
- srand(time(NULL));
- char memn[] = "client.c"; // имя объекта
- char *addr;
- int shm;
- int mem_size = 100; //размер области
- int buff[50];
- //открыть объект
- if ((shm = shm_open(memn, O_RDWR, 0666)) == -1 ) {
- printf("Opening error\n");
- perror("shm_open");
- return 1;
- } else {
- printf("Object is open: name = %s, id = 0x%x\n", memn, shm);
- }
- addr = mmap(0, mem_size, PROT_WRITE|PROT_READ, MAP_SHARED, shm, 0);
- if (addr == (char*)-1 ) {
- printf("Error getting pointer to shared memory\n");
- return 1;
- }
- for (int i = 0; i < 50; ++i) {
- buff[i] = rand() % 1001;
- }
- memcpy(addr, buff, 50 * sizeof(int));
- close(shm);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement