Xref: utzoo comp.unix.questions:5561 comp.unix.wizards:6496 Path: utzoo!utgpu!water!watmath!clyde!rutgers!princeton!phoenix!asjoshi From: asjoshi@phoenix.Princeton.EDU (Amit S. Joshi) Newsgroups: comp.unix.questions,comp.unix.wizards Subject: Help about shared memory Keywords: Shared memory IRIS (BSD?) Message-ID: <1739@phoenix.Princeton.EDU> Date: 15 Feb 88 08:00:20 GMT Organization: Princeton University, NJ Lines: 47 Hi, I wanted to share some data between two processes. I looked up the manual and found something called "shared memory". Could somebody tell me waht that is and how do I use it ? I naively tried something like this: typdef struct { int flag; char buf[80];} mydat; main() { mydat *dat; int sid,pid; if ((sid = shmget(IPC_PRIVATE,sizeof(mydat),IPC_CREAT)) < 0) { perror("no shared memory"); exit(1); } dat = (mydat *)shmat(sid,0,0); sprintf(dat->buf,"this is a test"); dat->flag = 1; if ((pid = fork()) < 0) { perror("no fork"); exit(1); } if (pid == 0) { printf("%s\n",dat->buf); } else { wait(0); printf("%s\n",dat->buf); } } I simply got a core dump and with dbx I found that the data->buf "was a nil pointer" or some such thing, and sprintf caused the crash due to a invalid memory access. Could somebody help me ?? Thanks, -- Amit Joshi BITNET | Q3696@PUCC.BITNET USENET | {seismo, rutgers}\!princeton\!phoenix\!asjoshi "There's a pleasure in being mad... which none but madmen know!" - St.Dryden