i ve searched quite a lot already and am aware that maybe i already came across some helpful answers but were unable to understand them...not really much of a programmer i am: )
the case is i would like to implement a daemon - background process totally independent of what is happening in the meantime - to parse data which are being received from the server (am writing IRC client) but to do it in non-blocking way using select().
Here s fragment of my code. But i cant get to printf under the comment //rest of the program
i hope it s understandable enough.
pID=fork();
if(pID < 0){
//failed to execute fork()
perror("Error while forking");
getchar();getchar();
exit(1);
}
if(pID > 0){
exit(0);
}
//child down here
umask(0);
//setting new session
sID = setpgid(0,0);
if(sID < 0){
perror("Error while setting new session");
getchar();getchar();
exit(1);
}
while(1){
sleep(1);
if((readReady = readReadiness(sockfd))==0)
continue;
else{
//here am going to recv() data from server
printf("I am child and parsing\n"); //testing if its in background -i would like it not to print to stdout (run in background)
}
}
//rest of the program down here
printf("Why isnt it printing to stdout ??\n");
should i use grandchild ? (double forking ?) or... ?
Thanks in advance