updates to articles
This commit is contained in:
parent
4c3b20b2f4
commit
c2bf60bebc
82 changed files with 30210 additions and 8 deletions
27
OS/C/Week5/q2opt.c
Normal file
27
OS/C/Week5/q2opt.c
Normal file
|
@ -0,0 +1,27 @@
|
|||
#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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue