-1

I have an application which uses mmap for ipc. Can I run this application multiple times? Will it have any side effects ?

My application scenario: my application forks off a child process whose job is to always kill the parent process randomly but it should do this in controlled manner, for example setting a variable in parent process which indicates the child process to kill the parent process (here comes the mmap). The parent process has a signal handler where it can resume the application again the child process kills the parent process it continues... Can any one help me? thanks in adavnce

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105

1 Answers1

0

Whether running your application multiple times will have side effects or not depends on how you implement it. Please have a look at this answer. It contains a lot of helpful information. For example:

mmap is great if you have multiple processes accessing data in a read only fashion from the same file [...]

This mean: If you want to use the same shared memory for multiple parent/child pairs, then you need to synchronize access to that shared memory. Please have a look at this Q&A on how to do that. Of course, you have to make sure, that each parent/child pair uses its own variables in the shared memory.

Another option is to use a separate shared memory segment for each parent/child pair. You could do this, for example, by making the process ID of the parent process a part of the shared memory file name. Then, when you fork the child process, you pass the process ID (or the shared memory file name) to the child process, so that parent and child know which shared memory to use in order to comunicate to each other.

Community
  • 1
  • 1
honk
  • 9,137
  • 11
  • 75
  • 83