Information on use of Netsys.shm_open
Johan Mazel <[email protected]> Tue, 23 Mar 2010 19:15:53 +0100
| Newsgroups | gmane.comp.lang.ocaml.lib.net.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi
I'm trying this little piece of code to open a shared memory and modify it.
The code looks like this :
open Unix
open Bigarray.Array1
let _ =
Printf.printf("Test shared memory\n");
if (Netsys.have_posix_shm () = false) then
Printf.printf "No POSIX SHM\n"
else
(
Printf.printf "POSIX SHM OK\n";
let shm_name = "/shm_test" in
let right_list = ref [] in
right_list := Netsys.SHM_O_CREAT :: !right_list;
right_list := Netsys.SHM_O_RDWR :: !right_list;
ignore(
try
(
Printf.printf "Netsys.shm_open call\n";
let sd = Netsys.shm_open shm_name !right_list 1
in
Printf.printf "Netsys.shm_open ok\n";
let my_big_array = Bigarray.Array1.map_file sd
Bigarray.char Bigarray.c_layout true 100 in
let big_array_size = Bigarray.Array1.dim
my_big_array in
Printf.printf "Size of BigArray: %d\n"
big_array_size;
Bigarray.Array1.set my_big_array 0 'a';
)
with
| Unix_error (_ , invoked_function , shm_name_failure)
->
(
Printf.printf
"Opening failed through using function
%s on SHM %s\n"
invoked_function
shm_name_failure
;
)
);
Printf.printf "Shared memory tested\n";
)
I can create the shared memory file descriptor, but only once.
When I try to access it again (y rzlaunching my program, there is an error
on shm_open.
I have to guess about a cause to this problem: first, I did not set the
right in the right manner and second, I do not use unlink.
The doc about the permissions is very light in this page (
http://projects.camlcity.org/projects/dl/ocamlnet-2.2.9/doc/html-main/Netsys.html).
I tried with with 0, 1, 777 and none of these are working.
For the unlink function, my understanding is that it destroys the file. But
maybe, it has the same behviour as "close" in C for a file descriptor.
Thanks in advance for your time.
Johan Mazel
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Ocamlnet-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ocamlnet-devel