Skip to content

Instantly share code, notes, and snippets.

@timothyhahn
Created February 14, 2013 17:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timothyhahn/4954487 to your computer and use it in GitHub Desktop.
Save timothyhahn/4954487 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <unistd.h>
int main(int argc, char *argv[]) {
int status;
int parent_pid = getpid();
int child_pid = fork();
if(!child_pid) { // If Child
printf("child\n");
char * send_buffer;
send_buffer = (char*) malloc(6);
send_buffer = "Hello";
long returnval = syscall(292, parent_pid, sizeof(char*) * 6, send_buffer);
printf("Child: return val %d\n", returnval);
printf("Child: Message sent.\n");
return 0;
} else { // If Parent
waitpid(child_pid, &status,0);
char * recv_buffer;
recv_buffer = (char*) malloc(6);
long returnval = syscall(293, child_pid, sizeof(char*) * 6, recv_buffer);
printf("Parent: return val %d\n", returnval);
printf("Parent: Message received - %s\n", recv_buffer);
return 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment