creating a child and parent process
int main()
{
pid_t cpid, w;
int status;
CreateSocket(); // it recievs data from the client
cpid = fork();
if (cpid == -1) {
perror("fork");
exit(EXIT_FAILURE);
}
if (cpid == 0) { /* Code executed by child */
CHECKTASKS(); //timer created for calling the task for every 2ms,10
} else {
do {
w = waitpid(cpid, &status, WUNTRACED | WCONTINUED);
if (w == -1) {
perror("waitpid");
exit(EXIT_FAILURE);
}
if (WIFEXITED(status)) {
printf("exited, status=%d\n", WEXITSTATUS(status));
} else if (WIFSIGNALED(status)) {
printf("killed by signal %d\n", WTERMSIG(status));
} else if (WIFSTOPPED(status)) {
printf("stopped by signal %d\n", WSTOPSIG(status));
} else if (WIFCONTINUED(status)) {
printf("continued\n");
}
} while (!WIFEXITED(status) && !WIFSIGNALED(status));
exit(EXIT_SUCCESS);
}
}
I created a child process and I am calling a CreateSocket(); // it recievs data from the client via the ip address and port number. I am calling this before creating a child process. If i do like that- will it be a parent process ?? I am calling a another function after creating a child process i.e CHECKTASKS(); //timer created for calling the task for every 2ms,10ms and 100ms// to run in the background . Is the CHECKTASKS will be running in the background as a separate process. Is it possible if I code like above in c for linux OS ??
windows_7 hemanth1989 is online now Report This Post
|