Created
February 14, 2013 17:29
-
-
Save timothyhahn/4954487 to your computer and use it in GitHub Desktop.
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 <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