fork(1) download
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <sys/types.h>
  4.  
  5. int main()
  6. {
  7. pid_t c1, c2;
  8. float a;
  9.  
  10. printf("Enter value of a: ");
  11. scanf("%f", &a);
  12.  
  13. c1 = fork();
  14.  
  15. if (c1 == 0)
  16. {
  17. printf("First Child (Circle)\n");
  18. printf("Area of Circle = %.2f\n", 3.14 * a * a);
  19. printf("Perimeter of Circle = %.2f\n", 2 * 3.14 * a);
  20. return 0;
  21. }
  22.  
  23. c2 = fork();
  24.  
  25. if (c2 == 0)
  26. {
  27. printf("Second Child (Square)\n");
  28. printf("Area of Square = %.2f\n", a * a);
  29. printf("Perimeter of Square = %.2f\n", 4 * a);
  30. return 0;
  31. }
  32.  
  33. return 0;
  34. }
  35.  
Success #stdin #stdout 0s 5324KB
stdin
Standard input is empty
stdout
Enter value of a: Enter value of a: Second Child (Square)
Area of Square = 0.00
Perimeter of Square = 0.00
Enter value of a: First Child (Circle)
Area of Circle = 0.00
Perimeter of Circle = 0.00