Skip to content

Commit

Permalink
made lab9
Browse files Browse the repository at this point in the history
  • Loading branch information
babadzakich committed Dec 24, 2024
1 parent 342fb93 commit 742115e
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions 23213/a.chuvashov/lab9/lab9.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

int main(int argc, char** argv) {
if (argc != 2) {
fprintf(stderr, "Wrong amount of arguments\n");
return -1;
}

pid_t pid;
if ((pid = fork()) > 0) {
wait(NULL);
printf("This is parent process\n");
} else if (pid == 0) {
execl("cat", "cat", argv[1], NULL);
perror("Couldn`t exec");
return -1;

} else {
perror("Couldn`t fork");
return -1;
}
return 0;
}

0 comments on commit 742115e

Please sign in to comment.