Skip to content

Instantly share code, notes, and snippets.

@karupanerura
Created October 3, 2015 15:57
Show Gist options
  • Save karupanerura/9426020577a8b09bb71d to your computer and use it in GitHub Desktop.
Save karupanerura/9426020577a8b09bb71d to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <dlfcn.h>
#include <sys/types.h>
int main(void) {
void *handle = dlopen("/usr/lib/libc.dylib", RTLD_LAZY);
unsigned int (*mysleep)(unsigned int) = dlsym(handle, "sleep");
int (*myfork)(void) = dlsym(handle, "fork");
void (*mywait)(int*) = dlsym(handle, "wait");
pid_t (*mygetpid)(void) = dlsym(handle, "getpid");
int pid = myfork();
if (pid == 0) {
printf("[%d] yay!\n", mygetpid());
mysleep(1);
printf("[%d] yay!\n", mygetpid());
return 0;
}
printf("[%d] pid:%d\n", mygetpid(), pid);
printf("[%d] wait...\n", mygetpid());
int status;
mywait(&status);
printf("[%d] done! status:%d\n", mygetpid(), status);
dlclose(handle);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment