I have encountered an issue when trying to make a duplicate check function.
The main objective is to store data from child process (based on the check() function result that returns true or false) to parent process. I already tried global variables but didn't work.
This is my code :
...
for(j=0; j<indIP; j++)
{
fflush(stdout);
if (!(fork()))
{
char* this_ip = strdup(ip[j]);
if(is_duplicate_check(this_ip,"file1"))
{
if(debugLevel >= 2) printf("Duplicate IP %s\n", this_ip);
}
else if( is_duplicate_check(this_ip,"file2"))
{
if(debugLevel >= 2) printf("Duplicate IP %s\n",this_ip);
}
else
{
if(debugLevel >= 2) printf("Checking IP [%d of %d] -> [%s]\n",current_combo,possible_combinations,ip[j]);
checkauth(this_ip);
}
exit(0);
}
else
{
numforks++;
current_combo += trys;
if (current_combo > possible_combinations)
{
break;
}
if (numforks >= maxf)
{
wait(NULL);
numforks--;
}
}
indInterface++;
if(indInterface>=countInterface) indInterface=0;
}
puts("Finalizing...");
while(numforks>0)
{
printf("Waiting for the child processes [%d] are finished ....\n", numforks);
wait(NULL);
numforks--;
}
puts("Script completed!");
return 0;
...
In short the program reads ips from a text file and checks them if they are a certain GEO CODE location. The is_duplicate_check
checks if the ip was not already checked, but it is working by storing ips to file1
and file2
, and when it arrives on 100.000 records it is making a lot of load.
Now all i want is to store ips from child process in an array and check before calling check()
function or not.
I already tried with
static int *glob_var;
glob_var = (int *) mmap(NULL, sizeof *glob_var, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
glob_var++;
printf("glob_var = [%d]\n",glob_var);
allways gives me something like (-1232557773525 ...), no use.
How can i solve this?