-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include <stdio.h> | ||
#include <unistd.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <sys/ipc.h> | ||
|
||
char* itoa(int val, int base){ | ||
|
||
static char buf[32] = {0}; | ||
int i = 30; | ||
for(; val && i ; --i, val /= base) | ||
buf[i] = "0123456789abcdef"[val % base]; | ||
return &buf[i+1]; | ||
|
||
} | ||
|
||
int main(int argc, char* argv[]) { | ||
if (argc == 1) | ||
exit(0); | ||
|
||
int n = atoi(argv[argc - 1]); | ||
int res = n / 2; | ||
printf("Halving, Current process id: %u, Current result: %d\n", getpid(), res); | ||
|
||
char* v[argc]; | ||
for (int i = 1; i < (argc-1) ; i++) { | ||
v[i-1] = argv[i]; | ||
} | ||
|
||
v[argc-2] = itoa(res, 10); | ||
v[argc-1] = NULL; | ||
|
||
execvp(v[0], v); | ||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include <stdio.h> | ||
#include <unistd.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <sys/ipc.h> | ||
|
||
char* itoa(int val, int base){ | ||
|
||
static char buf[32] = {0}; | ||
int i = 30; | ||
for(; val && i ; --i, val /= base) | ||
buf[i] = "0123456789abcdef"[val % base]; | ||
return &buf[i+1]; | ||
|
||
} | ||
|
||
int main(int argc, char* argv[]) { | ||
if (argc == 1) | ||
exit(0); | ||
|
||
int n = atoi(argv[argc - 1]); | ||
int res = n * n; | ||
printf("Squaring, Current process id: %u, Current result: %d\n", getpid(), res); | ||
|
||
char* v[argc]; | ||
for (int i = 1; i < (argc-1) ; i++) { | ||
v[i-1] = argv[i]; | ||
} | ||
|
||
v[argc-2] = itoa(res, 10); | ||
v[argc-1] = NULL; | ||
|
||
execvp(v[0], v); | ||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include <stdio.h> | ||
#include <unistd.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <sys/ipc.h> | ||
|
||
char* itoa(int val, int base){ | ||
|
||
static char buf[32] = {0}; | ||
int i = 30; | ||
for(; val && i ; --i, val /= base) | ||
buf[i] = "0123456789abcdef"[val % base]; | ||
return &buf[i+1]; | ||
|
||
} | ||
|
||
int main(int argc, char* argv[]) { | ||
if (argc == 1) | ||
exit(0); | ||
|
||
int n = atoi(argv[argc - 1]); | ||
int res = 2 * n; | ||
printf("Doubling, Current process id: %u, Current result: %d\n", getpid(), res); | ||
|
||
char* v[argc]; | ||
for (int i = 1; i < (argc-1) ; i++) { | ||
v[i-1] = argv[i]; | ||
} | ||
|
||
v[argc-2] = itoa(res, 10); | ||
v[argc-1] = NULL; | ||
|
||
execvp(v[0], v); | ||
} | ||
|