Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!samsung!uunet!europa.asd.contel.com!sura.net!haven!adm!news From: TAYBENGH%NUSDISCS.BITNET@cunyvm.cuny.edu Newsgroups: comp.unix.internals Subject: usable of attached shared memory (done by parent) in child process? Message-ID: <26156@adm.brl.mil> Date: 27 Feb 91 15:41:15 GMT Sender: news@adm.brl.mil Lines: 38 Dear Unix-Wizards, I have implemented a simple message-passing utility using SysV shared memory. I have an question of the use of shared memory after the process fork(). The question is: If a process fork a child process AFTER attaching the shared memory to its virtual addr say char *SHM, will SHM in the child process points to the same shared memory? The question can be illustrated in the follwoing C code segment: char *SHM; int pdata, /* data sent by parent */ cdata; /* data recv/stored by child */ int shmid; shmid = shmget(); .... SHM = shmat(shmid, 0, 0); if (fork()) { /* parent process */ memcpy(SHM, pdata, sizeof(data)); .... } else { /* child process */ memcpy(cdata, SHM, sizeof(data)); <--- is SHM (of child) still points to the same shared memory attached by parent?? ...... } Thanks in advance. - Beng Hang Dept of Information Systems and Computer Science National University of Singapore