I'm trying to compile 2 executable files. One of them is sampler and other one is collector. Sampler must be called from a child of collector. Sampler one writes some datas to shared memory and collector should read it from shared memory. I am using execlp to call Sampler, but I think I am doing something wrong. It does not write anything with the code below. But when I execute Sampler manually it writes datas to shared memory, then when I execute the collector it can read the data correctly. In shortly execlp function does not call the Sampler properly. Why?
pid = fork();
if (pid == 0) {
execlp("/home/gizux/Belgeler/ogr1grp14pro2/Sampler1","/home/gizux/Belgeler/ogr1grp14pro2/Sampler1", ShmID, NULL);
exit(0);
}
else
{
//collector codes come here
}
If I don't use execlp() and put Sampler's codes to there, it's working .
pid = fork();
if (pid == 0) {
ShmID = shmget(55667, 4*sizeof(int), IPC_CREAT | 0666);
if (ShmID < 0) {
printf("*** shmget error (server) ***\n");
exit(1);
}
ShmPTR = (int *) shmat(ShmID, NULL, 0);
if ((int) ShmPTR == -1) {
printf("*** shmat error (server) ***\n");
exit(1);
}
int random;
random = rand()%100+1;
ShmPTR[0] = r;
ShmPTR[1] = random;
r++;
random = 0;
printf("Sampler has filled %d %d in shared memory...\n",
ShmPTR[0], ShmPTR[1]);
exit(0);
}
else
{
//collector codes come here
}