Created
August 29, 2015 11:21
-
-
Save qnighy/b0e04ee807c71af0f67d 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 <stdbool.h> | |
#include <unistd.h> | |
#include <sys/types.h> | |
#include <sys/wait.h> | |
int main() { | |
// pid_t parent = getpid(); | |
while(true) { | |
pid_t child = fork(); | |
if(child < 0) { | |
fprintf(stderr, "fork() failed\n"); | |
return 1; | |
} | |
if(child == 0) { | |
execlp("date", "date", NULL); | |
} else { | |
int status; | |
waitpid(child, &status, 0); | |
} | |
} | |
return 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
#include <stdio.h> | |
#include <stdbool.h> | |
#include <unistd.h> | |
#include <spawn.h> | |
#include <sys/types.h> | |
#include <sys/wait.h> | |
int main() { | |
// pid_t parent = getpid(); | |
while(true) { | |
pid_t child; | |
char spawn_argv0[] = "date"; | |
char * const spawn_argv[2] = {spawn_argv0, NULL}; | |
int result = posix_spawnp( | |
&child, | |
"date", | |
NULL, | |
NULL, | |
spawn_argv, | |
environ); | |
if(result < 0) { | |
fprintf(stderr, "posix_spawnp() failed\n"); | |
return 1; | |
} | |
int status; | |
waitpid(child, &status, 0); | |
} | |
return 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
#!/usr/bin/make -f | |
EXECS = a b | |
CC = gcc | |
CFLAGS = -std=c99 -O2 -Wall -Wextra -ggdb | |
all: $(EXECS) | |
clean: | |
$(RM) $(EXECS) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment