Last active
August 29, 2015 13:56
-
-
Save jautero/9110592 to your computer and use it in GitHub Desktop.
Simple save command code.
This file contains 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 <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