Hi every one !
I have a little problem. I have to code a simple C application that creat a process and his child (fork()) and I have to do an operation. Parent initialize the values and child calculate. I write this :
#include <stdlib.h>
#include <signal.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
typedef struct {
int op1;
char op;
int op2;
}Operation;
Operation *varOP;
void finalResult()
{
float result = 0;
if(varOP->op == '+') result = (varOP->op1 + varOP->op2);
if(varOP->op == '-') result = (varOP->op1 - varOP->op2);
if(varOP->op == '*') result = (varOP->op1 * varOP->op2);
if(varOP->op == '+') result = (varOP->op1 / varOP->op2);
printf("%f",result);
}
int main () {
int p;
varOP = (Operation *)malloc(sizeof(Operation));
p = fork();
if(p == 0) // If child
{
signal(SIGUSR1, finalResult );
pause();
}
if(p > 0) // If parent
{
varOP->op = '+';
varOP->op1 = 2;
varOP->op2 = 3;
kill(p, SIGUSR1);
wait(NULL);
}
return 0;
}
But my child is never called. Is there something wrong with my code? Thanks for your help !