Created
October 11, 2014 08:12
-
-
Save kjmkznr/e7c7e3ccaf980876acfb 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 "libexample.h" | |
void helloworld() { | |
printf("Hello World\n"); | |
} |
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
void helloworld(); |
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
INSTALL = /usr/bin/install -c | |
prefix = /usr/local | |
libdir = $(prefix)/lib | |
default: | |
$(CC) -Wall -fPIC -c libexample.c | |
$(CC) -Wall -shared -Wl,-soname=libexample.so -o libexample.so libexample.o | |
clean: | |
@rm -f libexample.o libexample.so | |
install: | |
$(INSTALL) libexample.so $(libdir) | |
.PHONY: clean |
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
/* $ gcc -I. -L. -lexample test-fork.c -o test-fork */ | |
#include <libexample.h> | |
#include <stdio.h> | |
#include <stdio.h> | |
#include <unistd.h> | |
int main() { | |
int status; | |
printf("[Parent] PID is %d\n", getpid()); | |
printf("[Parent] "); | |
helloworld(); | |
while(1) { | |
pid_t pid = fork(); | |
if (pid == 0) { | |
printf("[Child] "); | |
helloworld(); | |
printf("[Child] PID is %d\n", getpid()); | |
sleep(1); | |
} else if (pid < 0) { | |
_exit(-1); | |
} else { | |
waitpid(pid, &status, 0); | |
} | |
} | |
} |
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
/* $ gcc -I. -L. -lexample test.c -o test */ | |
#include <libexample.h> | |
#include <stdio.h> | |
#include <stdio.h> | |
int main() { | |
helloworld(); | |
printf("PID is %d\n", getpid()); | |
printf("Press Any Key To Exit..."); | |
fgetc(stdin); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment