shared-memory

How do I pass virtual address to shmat() function in a guaranteed way

99封情书 提交于 2020-01-14 03:09:10
问题 I am using shmat() by using a virtual address. the first process calls a shmat with shmaddr as null and when it gets the virtual address of the data block it stores in another shared memeory place. the second process calls the shmat() with the virtaul address that was stored in shared memeory by the first process. The second process usually can attach to the same virtual address in most of the cases, but in one case I couldn't and shmat returned -1 and when I used gdb I saw that the address

C - fork() and sharing memory

微笑、不失礼 提交于 2020-01-12 13:47:14
问题 I need my parent and child process to both be able to read and write the same variable (of type int) so it is "global" between the two processes. I'm assuming this would use some sort of cross-process communication and have one variable on one process being updated. I did a quick google and IPC and various techniques come up but I don't know which is the most suitable for my situation. So what technique is best and could you provide a link to a noobs tutorial for it. Thanks. 回答1: Since you

How can I share existing memory with shm_open?

十年热恋 提交于 2020-01-12 07:21:05
问题 In Linux, I want to share some memory content of my process with other processes. one of the way to do this is using shm_open and mmap. like below. /* Create a new memory object */ fd = shm_open( "/bolts", O_RDWR | O_CREAT, 0777 ); if( fd == -1 ) { fprintf( stderr, "Open failed:%s\n", strerror( errno ) ); return EXIT_FAILURE; } /* Set the memory object's size */ if( ftruncate( fd, sizeof( *addr ) ) == -1 ) { fprintf( stderr, "ftruncate: %s\n", strerror( errno ) ); return EXIT_FAILURE; } /*

Designing a Queue to be a shared memory

拈花ヽ惹草 提交于 2020-01-12 01:43:26
问题 I'm attempting to design/implement a (circular) queue (in C) as a shared memory so that it can be shared between multiple threads/processes. The queue structure is as follows: typedef struct _q { int q_size; int q_front; int q_rear; int *q_data; }queue; Which supports the following functions: int empty_q(queue *q); int display_q(queue *q); int create_q(queue **q, int size); int delete_q(queue **q); int enqueue(queue *q, int data); int dequeue(queue *q, int *data); As per the queue size

Can I somehow share an asynchronous queue with a subprocess?

佐手、 提交于 2020-01-11 15:31:07
问题 I would like to use a queue for passing data from a parent to a child process which is launched via multiprocessing.Process . However, since the parent process uses Python's new asyncio library, the queue methods need to be non-blocking. As far as I understand, asyncio.Queue is made for inter-task communication and cannot be used for inter-process communication. Also, I know that multiprocessing.Queue has the put_nowait() and get_nowait() methods but I actually need coroutines that would

Shared memory access control mechanism for processes created by MPI

守給你的承諾、 提交于 2020-01-11 04:15:30
问题 I have a shared memory used by multiple processes, these processes are created using MPI . Now I need a mechanism to control the access of this shared memory. I know that named semaphore and flock mechanisms can be used to do this but just wanted to know if MPI provides any special locking mechanism for shared memory usage ? I am working on C under Linux. 回答1: MPI actually does provide support for shared memory now (as of version 3.0). You might try looking at the One-sided communication

shmat() is returning a different “shmaddr” for same “shmkey”

匆匆过客 提交于 2020-01-10 05:18:05
问题 Here's my setup... /* Bounded Buffer item structure */ struct item { int id; /* string index value */ char str[80]; /* string value */ }; /* Structure for the shared memory region */ typedef struct { int debug; /* debug flag */ int in; /* index of next empty slot */ int out; /* index of next full slot */ char MUTEXname[32]; /* name of the MUTEX semaphore */ char EMPTYname[32]; /* name of the EMPTY semaphore */ char FULLname[32]; /* name of the FULL semaphore */ struct item buff[BUFFSIZE]; /*

boost::interprocess scoped_allocator AND Containers of containers NOT in shared memory

谁说我不能喝 提交于 2020-01-09 08:04:29
问题 I have a similar question as before in boost::interprocess Containers of containers NOT in shared memory and How to I create a boost interprocess vector of interprocess containers but this time I like to use my class, which uses a scoped_allocator, also on the heap and shared memory. The solution to my first question was to use a template class with an allocator type In my second previous question it turned out that using a scoped_allocator together with a container of containers within the

boost::interprocess scoped_allocator AND Containers of containers NOT in shared memory

℡╲_俬逩灬. 提交于 2020-01-09 08:03:40
问题 I have a similar question as before in boost::interprocess Containers of containers NOT in shared memory and How to I create a boost interprocess vector of interprocess containers but this time I like to use my class, which uses a scoped_allocator, also on the heap and shared memory. The solution to my first question was to use a template class with an allocator type In my second previous question it turned out that using a scoped_allocator together with a container of containers within the

boost::interprocess scoped_allocator AND Containers of containers NOT in shared memory

南笙酒味 提交于 2020-01-09 08:03:27
问题 I have a similar question as before in boost::interprocess Containers of containers NOT in shared memory and How to I create a boost interprocess vector of interprocess containers but this time I like to use my class, which uses a scoped_allocator, also on the heap and shared memory. The solution to my first question was to use a template class with an allocator type In my second previous question it turned out that using a scoped_allocator together with a container of containers within the