Advertisement
Guest User

Untitled

a guest
Apr 1st, 2015
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #include "stdio.h"
  2. #include "stdlib.h"
  3. #include <unistd.h>
  4. #include "prime.h"
  5.  
  6. int main(int argc, char *argv[])
  7. {
  8. int number, childNum;
  9.  
  10. if (!atoi(argv[1])) {
  11. printf("Please use a valid integer as an argument!");
  12. exit(1);
  13. }
  14.  
  15. int pid = fork();
  16.  
  17. if (pid == 0) {
  18. wait(childNum);
  19. morph(argv[1]);
  20. }
  21.  
  22. else {
  23. if (childNum == 0) {
  24. printf("The input number is not a prime number!");
  25. exit(1);
  26. }
  27. else if (childNum == 1) {
  28. printf("The input number is a prime number!");
  29. exit(1);
  30. }
  31. else if (childNum == 2) {
  32. printf("Please input a number greater than 2!");
  33. exit(1);
  34. }
  35. }
  36. }
  37.  
  38. void morph(char *number)
  39. {
  40. char *primeArgv[] = {
  41. "isPrime.exe",
  42. number,
  43. NULL,
  44. };
  45.  
  46. execvp("isPrime.exe",primeArgv);
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement