Reputation: 21
I want to run a C function in background but I want it to keep it running when the main
function exits.
I tried following:
pthread_detach
, a detached thread exits if the main
function calls exit()
instead of pthread_exit
.deamon()
: It runs the code in background but not in parallel.So, what is the simplest way to run a C function in parallel/background even after my main
function exits?
Upvotes: 2
Views: 2066
Reputation: 2106
Once main returns OS will delete all threads within process. To continue thread use fork to create child process.
Upvotes: 1
Reputation: 70971
So, what is the simplest way to run a C function in parallel/background even after my
main
function exits?
Exit main()
by calling pthread_exit()
.
Upvotes: 1