int main(int argc, char *argv[])
{
int shmid; /* Segment ID */
char *shmbuf; /* Address in process */
/* Expect an segment id on the command line */
if (argc != 2) {
puts("USAGE: atshm <identifier>");
exit(EXIT_FAILURE);
}
shmid = atoi(argv[1]);
/* Attach the segment */
if ((shmbuf = shmat(shmid, 0, 0)) < (char *)0) {
perror("shmat");
exit(EXIT_FAILURE);
}
/* Where is it attached? */
printf("segment attached at %p\n", shmbuf);
/* See, we really are attached! */
system("ipcs -m");