0

I have the code below, but I need that exit(status) return a float but WEXITSTATUS doesn't receive a float cause status must be int, so what's the solution please?

scanf("%f%f",&f,&g);
        P = fork();
        if(P == 0){
            printf("\nje suis le fils multiplication: PID = %d\n", getpid() );
            printf("mon pere: PID = %d\n", getppid() );
            resultat2 = f * g;
            exit(resultat2);
        }else if(P < 0){
            printf("FORK a echoue\t");
            exit(EXIT_FAILURE);
        }else{
            printf("\nje suis le pere : PID = %d\n", getpid() );
            printf("mon fils: PID = %d\n", P );
            P = wait(&status);
            if(WIFEXITED(status))
                printf("le produit = %d \n", WEXITSTATUS(status));
        }
usr1234567
  • 21,601
  • 16
  • 108
  • 128
Hind Dev
  • 115
  • 2
  • 7
  • Yeah, French code. It would help if you use English texts and additional explain what the program is supposed to do. – usr1234567 Apr 04 '15 at 14:11

1 Answers1

0

The exit status is not meant to transport results of calculations. It is meant to indicate successful termination with 0 and non-successful termination with a value bigger then zero. You can pass different non-zero values, to give back error codes.

Don't abuse this mechanism. You should print your result and parse that in the parent.

usr1234567
  • 21,601
  • 16
  • 108
  • 128