Port-amiga archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
SHM test program: please run
Please run this program and tell me what happens.
(Extract the 3 files: shm1.c, shm2.c, Makefile; then "make test")
Regards,
Ignatios
--
* Progress (n.): The process through which Usenet has evolved from
smart people in front of dumb terminals to dumb people in front of
smart terminals. -- obs%burnout.demon.co.uk@localhost (obscurity)
CC=gcc
COPTS=-O2
all: shm1 shm2
clean: ; rm shm1 shm2
test: all
./shm1
./shm2
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <stdio.h>
int
main(int argc, char *argv[]) {
int myid;
char *buf;
void *p;
myid = shmget((key_t)0x4712, 80, IPC_CREAT| 0700);
if (myid == -1) {
perror("shmget");
exit(1);
}
printf("Returned %d\n", myid);
p = shmat(myid, 0, 0);
if (p == (void *)-1) {
perror("shmat");
exit(1);
}
printf("Returned 0x%08x\n", p);
strncpy((char *)p,
"The quick brown fox jumps over the lazy dogs' back", 80);
}
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <stdio.h>
int
main(int argc, char *argv[]) {
int myid, rc;
void *p;
myid = shmget((key_t)0x4712, 80, 0700);
if (myid == -1) {
perror("shmget");
exit(1);
}
printf("Returned %d\n", myid);
p = shmat(myid, 0, 0);
printf("%-80s\n", p);
rc = shmctl(myid, IPC_RMID, 0);
if (rc == -1) {
perror("shmctl");
exit(1);
}
}
Home |
Main Index |
Thread Index |
Old Index