I'm having this weird issue right now, basically I'm trying to execute two functions in parallel.
The small code snippet that has this issue has this purpose: The child function listens to some events as long as the parent function/process has not finished its own task, in case of a new event happening in the child process/function the child process should terminate the whole program.
Here is the example code snippet:
#include<stdio.h>
#include<stdlib.h>
void send();
int main(void)
{
send();
}
void send()
{
if( fork() ) { /*child process */
keep_checking_status(); /*listens to audio related events, and terminate the whole program when some specific kind of event occurs */
}
else {
/* Parent Process */
/* The parent process executes different other functions, lines of code here */
/* code lines */
func1();
func2();
func3();
func4();
/* More lines of code */
/* And when no event occurs in the child which means the program is still running and the parent process almost executed all the code it was supposed to do, so finally exit(0); */
exit(0);
}
}
Now the problem is that instead of executing the parent only once, the parent process goes into infinite condition, and doesn't execute all the code to reach to the last line which is func4() or exit(0); and terminate peacefully.
Again i want the child process to listen to some specific audio events that i have taken care of, and the parent process should only execute the lines of code inside it and exit.
Also there is no while loop in the parent process , it is just a code that executes and computes some other things, and that is why it feel very strange.
I did looked into some examples of fork() being used differently , i tried them but still same issue.
Edit: (SOLVED):
Ok after renaming the function void send(); to void send11(); , it worked now as I wanted.
It seems like the libraries that I'm using i.e libcurl etc have some function like send() or they have included the linux system all send() which was creating this issue for me. My bad.
If anyone can answer why this behavior of never terminating , please post your detail answer, because usually the compiler report the conflicting of names but in my case it didn't reported any errors instead the program went into infinity.