From: Lionel Perrin <perrin@domain.hid>
Cc: xenomai@xenomai.org
Subject: Re: [Xenomai-help] shm_open, ftruncate
Date: Tue, 06 Jun 2006 13:53:11 +0200 [thread overview]
Message-ID: <44856CA7.30802@domain.hid> (raw)
In-Reply-To: <17540.21517.871383.751462@domain.hid>
[-- Attachment #1: Type: text/plain, Size: 916 bytes --]
> > - Will this shared memory be accessible to non rt-task ?
> > - What's the simplest way to share information with a non rt-task ?
>
> Shared memory are also accessible to non-rt tasks. Since user-space
> realtime and non-realtime threads from the same process reside in the
> same address space, the simplest way to share information from rt to
> non-rt tasks is to create them as threads of the same process.
>
Ok, but I figure out that it's possible to share memory between
processes ? (rt and non rt?)
For the moment, i focus on sharing between two rt tasks, but in vain :(
I still have a ftruncate error (EBADF) when i launch two rt processes...
I explain :
I've tried the attached program. I've added a sleep(1) between mmap and
munmap. I launch this appli twice with
>> shm_test &
>> shm_test &
For the second one, I got "ftruncate: Invalid argument". Am I the only
one to have this problem ?
[-- Attachment #2: test_shm.c --]
[-- Type: text/plain, Size: 1513 bytes --]
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#define MAX_LEN 10000
struct region { /* Defines "structure" of shared memory */
int len;
char buf[MAX_LEN];
};
struct region *rptr;
int fd;
int main(int argc, const char *argv[])
{
int fd, status;
mlockall(MCL_CURRENT|MCL_FUTURE);
/* Create shared memory object and set its size */
fd = shm_open("/myregion", O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
if (fd == -1) {
perror("shm_open");
exit(EXIT_FAILURE);
}
if ((status = ftruncate(fd, sizeof(struct region))) == -1) {
/* Handle error */;
perror("ftruncate");
close(fd);
status = EXIT_FAILURE;
goto close_and_unlink;
}
/* Map shared memory object */
rptr = (struct region *) mmap(NULL,
sizeof(struct region),
PROT_READ | PROT_WRITE,
MAP_SHARED,
fd,
0);
if (rptr == MAP_FAILED) {
/* Handle error */;
perror("mmap");
status = EXIT_FAILURE;
goto close_and_unlink;
}
/* Now we can refer to mapped region using fields of rptr;
for example, rptr->len */
sleep(1);
munmap(rptr, sizeof(struct region));
close_and_unlink:
close(fd);
shm_unlink("/myregion");
return status;
}
next prev parent reply other threads:[~2006-06-06 11:53 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-06-02 15:29 [Xenomai-help] shm_open, ftruncate Lionel Perrin
2006-06-02 16:29 ` Gilles Chanteperdrix
2006-06-02 17:17 ` Gilles Chanteperdrix
2006-06-05 13:49 ` Lionel Perrin
2006-06-05 15:55 ` Gilles Chanteperdrix
2006-06-06 11:53 ` Lionel Perrin [this message]
2006-06-06 12:21 ` Gilles Chanteperdrix
[not found] ` <44859C28.3090600@domain.hid>
[not found] ` <17541.49945.431732.834139@domain.hid>
2006-06-07 12:55 ` Lionel Perrin
2006-06-07 14:52 ` Gilles Chanteperdrix
2006-06-09 8:56 ` Lionel Perrin
2006-06-09 11:46 ` Gilles Chanteperdrix
2006-06-09 12:28 ` Gilles Chanteperdrix
2006-06-09 13:18 ` Lionel Perrin
2006-06-06 18:08 ` Gilles Chanteperdrix
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=44856CA7.30802@domain.hid \
--to=perrin@domain.hid \
--cc=xenomai@xenomai.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.