/************************************************* * Lock a segment of shared memory. * * Please see the source of shmgrab.c for more info * * * * Copyright Yves Dorfsman 1999. *************************************************/ /*** #define _INCLUDE_HPUX_SOURCE ***/ #include #include #include #include #include #include #include void usage(char*); main(int argc, char** argv) { int shm_id; if (argc != 2) { usage(argv[0]); return -1; } shm_id = atoi(argv[1]); printf("Locking the shared memory segment with ID: %d\n", shm_id); /** SHM_LOCK = 3, don't know why the include of shm.h doesn't work **/ /** The above line is for HPUX **/ if ( shmctl(shm_id, SHM_LOCK, 0) != 0) { perror(argv[0]); return errno; } else { printf("Shared memory ID = %d now locked.\n", shm_id); printf("Please remember to release it with \'ipcrm -m ID\'.\n\n"); } return 0; } void usage(char* progname) { fprintf(stderr, "\n\t%s:\tSyntax error.\n", progname); fprintf(stderr, "\n\tUsage:\t%s ID\n\n", progname); fprintf(stderr, "\tID is a shared memory segment ID.\n\n", progname); }