fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <sys/wait.h>
  4. #include <sys/types.h>
  5. int main() {
  6. int n;
  7. printf("Enter the number: ");
  8. scanf("%d",&n);
  9. pid_t pid=fork();
  10. if (pid==0){
  11. if (n%2!=0) printf("Odd number.\n");
  12. else printf("Not odd number.\n");
  13. }
  14. else if (pid<0){
  15. printf("Fork not active.\n");
  16. }
  17. else {
  18. if (n%2==0) printf("Even number.\n");
  19. else printf("Not even number.\n");
  20. }
  21. return 0;
  22. }
Success #stdin #stdout 0s 5320KB
stdin
45
stdout
Enter the number: Not even number.
Enter the number: Odd number.