add fork and comment translate

This commit is contained in:
Christoph J. Scherr 2024-05-16 13:39:50 +02:00
parent 37bbe98da4
commit add1185efc
3 changed files with 26 additions and 0 deletions

View File

@ -8,3 +8,4 @@ include_directories(${PROJECT_SOURCE_DIR})
add_executable( hello src/hello.c ) add_executable( hello src/hello.c )
add_executable( args src/args.c ) add_executable( args src/args.c )
add_executable( translate src/translate.c ) add_executable( translate src/translate.c )
add_executable( fork src/fork.c )

21
src/fork.c Normal file
View File

@ -0,0 +1,21 @@
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
int main(int argc, char *argv[]) {
pid_t pid;
if ((pid = fork()) < 0) {
fprintf(stderr, "ERROR: Fork failed (%s)\n", strerror(errno));
return 1;
}
if (pid != 0) {
printf("Parent process (%d) of child process (%d)\n", getpid(), pid);
} else {
printf("Child process (%d)\n", getpid());
}
return 0;
}

View File

@ -1,3 +1,7 @@
/*
* Read from stdin. replace all occurences of arg 1 with arg2.
*/
#include <stdio.h> #include <stdio.h>
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {