how can I print the exit status of the child program within the father process? ( after wait() )
the code to get the exit status of the child process works, but I don't know how to print it after
#include <stdio.h> // printf
#include <unistd.h> // getpid
#include <stdlib.h>
void childProcess(void);
void fatherProcess(int childpid);
int num1, num2, oper_inizializzata;
int main() {
int pid=fork();
if (pid==0) {
childProcess();
} else if (pid>0) {
fatherProcess(pid);
} else { // pid<0
printf("Creazione del processo figlio fallita!\n");
}
}
void childProcess(void)
{
printf("Inserisci il valore del primo numero\n");
scanf("%d",&num1);
printf("Inserisci il valore del secondo numero\n");
scanf("%d",&num2);
printf("Scegli tra 1 o 2 per il valore della variabile\n");
scanf("%d",&oper_inizializzata);
if(oper_inizializzata==1){
int num1piu2=num1+num2;
printf("num1 + num2 e' %d\n", num1piu2);
exit(num1piu2);
}
else if(oper_inizializzata==2){
int num1per2=num1*num2;
exit(num1per2);}
}
void fatherProcess(int childpid)
{
wait();
//print exit status here
}