28 lines
694 B
C
28 lines
694 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
#include <sys/types.h>
|
|
#include <sys/wait.h>
|
|
|
|
int compare_strings(const void *a, const void *b) {
|
|
return strcmp(*(const char **)a, *(const char **)b);
|
|
}
|
|
|
|
int main(int argc, char *argv[]) {
|
|
pid_t pid = fork();
|
|
if (pid == 0) {
|
|
qsort(&argv[1], argc - 1, sizeof(char *), compare_strings);
|
|
printf("Child Sorted:\n");
|
|
for (int i = 1; i < argc; ++i)
|
|
printf("%s\n", argv[i]);
|
|
exit(EXIT_SUCCESS);
|
|
} else {
|
|
wait(NULL);
|
|
printf("\nParent Unsorted:\n");
|
|
for (int i = 1; i < argc; ++i)
|
|
printf("%s\n", argv[i]);
|
|
}
|
|
return 0;
|
|
}
|