I read that fork intiates a process and exec executes it and exit exits the process and wait command makes the parent wait for the child's exit status.
But I am unable to correlate what does that actually mean?
When I execute a command in shell(eg.vi main.cpp ,cat foo,mkdir DIR)..are these different stages when this command is being executed?
Where all these sysstem calls are used?
It could be very beginner question....but I am clueless....Please help.
system calls such as that tend to be very well documented in the POSIX libraries (which overlies C might I add): http://pubs.opengroup.org/onlinepubs/009695399/functions/fork.html
Upon a successful call to fork(), the process is already running. You have to use logic to determine which process your current logic is running in by checking its return status.
exec[v] on the other hand is use to start a separate process with logic stored elsewhere (usually an ELF binary): http://pubs.opengroup.org/onlinepubs/009695399/functions/exec.html
Exit can exit the process but I wouldn't recommend such a sudden stop-all function. You have to clean up after yourself in any given context or your program might have unwanted side-effects. You can use atexit() but it's generally not that great for threaded environments and isn't very well featured. http://pubs.opengroup.org/onlinepubs/009695399/functions/exit.html