LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   creating a child and parent process (https://www.linuxquestions.org/questions/linux-newbie-8/creating-a-child-and-parent-process-4175496755/)

hemanth1989 03-02-2014 11:45 AM

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 ??

I want the CreateSocket and CHECKTASKS to take place parallely. Is it possible in the above code ??

unSpawn 03-02-2014 04:09 PM

Please post your thread once and in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place. This thread should be closed because it is a duplicate of https://www.linuxquestions.org/quest...ss-4175496759/.

hemanth1989 03-02-2014 04:13 PM

I am extremely sorry for that. I am new here and don't know how to delete my thread. so it is in two forums.

unSpawn 03-02-2014 04:30 PM

You did it once before with one topic. Now you are aware you should not.
That's enough, no need for deletions, no harm done.
Just continue in your first thread.


All times are GMT -5. The time now is 10:44 PM.