|
int segment_id = 0;
int
main()
{
int size = 1024;
int pid = fork();
if (pid == 0)
{
segment_id = shmget(IPC_PRIVATE, size,
S_IRUSR | S_IWUSR);
char *shared = (char *)shmat(segment_id, NULL, 0);
sprintf(shared, "Operating system concepts!\n");
shmdt(shared);
}
else
{
int stat;
waitpid(pid, &stat, 0);
char *attach = shmat(segment_id, NULL, S_IRUSR|S_IWUSR);
printf("%s\n", attach);
shmctl(segment_id, IPC_RMID, NULL);
}
return 0;
}
请问我在子进程里使用shmget,并向该区域写字符串,为何在父进程里读取不到该字符串呢?
请尽量详细说明。
谢谢! |
|