The fork() Unix function spawns a child process which is an exact duplicate of the parent process. Fork returns twice, once in the parent and once in the child. In the child, fork returns 0; in the parent, fork returns the Process ID (pid) of the new child. After returning from fork, both parent and child continue running simultaneously but with entirely separate address spaces. This means that neither process will be able to communicate with the other process (at least not thru shared memory).
Keep in mind that the child process is a copy of the parent. Both will have the same code and will continue running from the same spot (at the return from fork), but they will be distinct processes.
The exec() Unix function replaces the current process with a new process by running a specified program. A call to exec will never return (unless there is an error).
The wait() and waitpid() Unix functions cause the current process to block, waiting until a child process terminates.
// this is the child!
One way to tokenize a string in C is to use the stdlib's strtok function. IT IS DANGEROUS, so be careful when using it. It has a few major problems:
Keeping these in mind, it is still possible to use strtok effectively. Here's how you use it:
I have a small website with some example Go code here: golangpatterns.info. Of particular interest for this class is:
Here's some example implementations in various languages. They are kinda interesting: http://dada.perl.it/shootout/prodcons_allsrc.html