I've problem with this code because this cycle not passing arguments correctly to son process and generate some error with fork.
nproc is numer process to create as 5 for example x is set to 1 value and i want to pass to my new process as 1,2,3 therefore every process as number and write it on file ...
I don't know can i do .. please help
but second parameter righeoperazione is 5 and is passed correct but because is always same father code where i put 2 type int and converted string to exec
/* father process*/
char param[0]="";
char param1[0]="";
for (i=0 ; i<NPROC ; i++) {
pid=fork();
if (pid==-1) { // pid=-1; error process
write(STDOUT,"fork error pid -1 ", 18);
}
else if (pid==0) {
sprintf(param1,"%d",x);
sprintf(param,"%d",righeoperazioni);
execl("processore.x","processore.x",¶m,¶m1,(char *)NULL);
write(STDOUT,"fork error ", 11);
}
else { write(STDOUT,"fork error else ", 15); }
x++;
}
int main(int argc, char *argv[]) { // son process
int nump=0;
int righe;
int oper=0;
char nome[10];
char temp[10];
char temp1[10];
nump=atoi(argv[2]); //
oper=atoi(argv[1]); //
righe=oper;
sprintf(nome,"%d",getpid());
int report = openFile(nome,O_CREAT | O_RDWR,S_IRUSR | S_IWUSR);
sprintf(temp,"%d",nump);
sprintf(temp1,"%d",oper);
stampa(report,"Number processo : ",18);
stampa(report,temp,strlen(temp));
stampa(report,"\Number comandi : ",18);
stampa(report,temp1,strlen(temp1));
stampa(report,"\n",1);
son code that capture 2 parameters (stampa is same as write but with -1 control)