Skip to content

Instantly share code, notes, and snippets.

@arkadijs
Created February 24, 2015 07:29
Show Gist options
  • Save arkadijs/90fec6cff6ff5c525d8e to your computer and use it in GitHub Desktop.
Save arkadijs/90fec6cff6ff5c525d8e to your computer and use it in GitHub Desktop.
Dump SYSV shared memory segment to stdout
#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