/* print string at start of shared memory segment */ /* 21 Oct 1991 by Eric Grosse. Copyright (c) 1991 by AT&T. * Permission to use, copy, modify, and distribute this software for any * purpose without fee is hereby granted, provided that this entire notice * is included in all copies of any software which is or includes a copy * or modification of this software and in all copies of the supporting * documentation for such software. * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR AT&T MAKE ANY * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. */ #include #include #include #include main(int argc, char **argv) { char *shm; int n; if(argc!=2){ fprintf(stderr,"usage: shmid n\n"); exit(1); } n = atoi(argv[1]); shm = (char*)shmat(n, 0, SHM_RDONLY); if (shm == (char *)(-1) || shm == 0){ fprintf(stderr,"can't attach %d\n",n); exit(2); } printf("%.128s",shm); exit(0); }