由买买提看人间百态

topics

全部话题 - 话题: shmid
(共0页)
z*l
发帖数: 763
1
来自主题: WHU版 - [转载] 多进程编程2
【 以下文字转载自 Unix 讨论区 】
【 原文由 zhl 所发表 】
本令只能由有效UID等于shm_perm.cuid或shm_perm.uid的
进程或有效UID有合适权限的进程操作.
返回值:若调用成功则返回0,否则返回-1.
例子:本例包括上述所有共享内存操作系统调用:
#include
#include
#include
#define SHMKEY 74
#define K 1024
int shmid;
cleanup()
{
shmctl(shmid,IPC_RMID,0);
exit(0);
}
main()
{
int *pint;
char *addr1,*addr2;
extern char *shmat();
extern cleanup();
for (i=0;i<20;i++)
signal(i,cleanup);
shmid=shmget(SHMKEY,128*K,0777|IPC_CREAT);
addr1=shmat(shmid,0,0);
addr2=shmat(shm
r*****o
发帖数: 28
2
来自主题: Unix版 - SYSV shared memory question
I have a shared data structure like this:
struct s {
int ...
...
char *text;
}
While creating the shmid, is it possible to dynamically
allocate the shared memory according to the size of the char*?
Or I should change the structure to:
struct s{
int ...
...
char text[MAXLENTH];
}
and shmid = shmget(..., sizeof(s), ...) ???
(共0页)