Skip to content

Instantly share code, notes, and snippets.

@jautero
Last active August 29, 2015 13:56
Show Gist options
  • Save jautero/9110592 to your computer and use it in GitHub Desktop.
Save jautero/9110592 to your computer and use it in GitHub Desktop.
Simple save command code.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#DEFINE BUFSIZE 100
#DEFINE UNCODECMD "uncore %s %s core.%d"
/* Save program state as executable. Name of saved file is savename, returns 0 on success. */
int save(char *savename)
{
int cpid;
char buf[BUFSIZE];
char exepath[BUFSIZE];
cpid=fork();
if (cpid<0) return -1;
if (cpid==0) {
abort();
return 0; // Will start here when saved file is "loaded".
}
if (readlink("/proc/self/exe",exepath,BUFSIZE)<0) return -1;
exepath[BUFSIZE]='\0';
if (snprintf(buf,BUFSIZE,UNCORECMD,savename,exepath,cpid)<0)
return -1;
buf[BUFSIZE]='\0';
if (system(buf)!=0) return -1;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment