Hi,
I'm writing some code for my Pi and I need to launch a new binary and pass it some info to use during execution. I'd like to check my understanding of threads and processes before getting started. This is a new aspect of coding for me.
So I have some code which is all tested and is working just fine. Into this I want to insert some new code to launch the Pi's camera software, both the stills and video capture binaries (not at the same time though ) and also a binary that takes a string input and sends out an SMS via an attached 3G dongle.
I have tried and tested the three seperate binaries with much joy. Now I want to tie them together. From my research into threads and processes I'm pretty sure I want to launch the two binaries (camera and 3G) as processes and NOT threads. This being due to threads operating in the same address space and launching a new binary in this manner could cause the new application to overwrite data from the calling program. If I'm wrong or there are methods of doing this, please correct me. Examples/psudeo code would be a great help.
Based on the above I'm left with launching in processes. Most people seem to suggest doing this with fork() and exec(). This creates a duplicate of the calling process and then launches the new binary. Being a duplicate I guess it doesn't matter if anything from the [duplicated] calling process gets over written. The process does it's thing and then exits. Both process run concurrently on the processor and a block in one does not affect the other.
Is that last sentence true?
I'll be creating the child processes within a loop (probably a new process every 60 seconds). If the old process hasn't finished, possibly because it has become blocked) then I'll terminate the process from code and launch a new one. I don't want a bunch of blocked processes hanging around. For example, if there isn't a 3G connection, the binary for that bit tries to resend the sms. Whilst I can tell it not too I want the ability to kill the process incase something goes very wrong.
So my question is... does all that sound reasonible? Is my understanding correct? Is there a better way of doing it?
Ta muchly,
Ben