Created
February 24, 2015 07:29
-
-
Save arkadijs/90fec6cff6ff5c525d8e to your computer and use it in GitHub Desktop.
Dump SYSV shared memory segment to stdout
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <errno.h> | |
#include <string.h> | |
#include <unistd.h> | |
#include <sys/shm.h> | |
int main(int argc, char**argv) | |
{ | |
void *shm; | |
if (argc != 4) { | |
fprintf(stderr, "usage: %s shmid offset length\n", argv[0]); | |
return 1; | |
} | |
shm = shmat(atoi(argv[1]), NULL, SHM_RDONLY); | |
if (shm == (void*)-1) { | |
fprintf(stderr, "shmat() failed: %s\n", strerror(errno)); | |
return errno; | |
} | |
write(1, shm+atoi(argv[2]), atoi(argv[3])); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment