Maybe the title does not word the question so precisely: I know that when I run gcc foo.c GCC calls other sub-programs that do all the work for it, making the main gcc program just an interface. But how exactly is this done?
Does it use system or exec or some other function? The reason I want to know this because I want to build a web crawler based on a similar system, where there would be a interface program and several other sub-programs like crawl and download.
I’m sorry if this question has already been asked but I didn’t find it using search or the “Questions with similar titles”.
Thank you in advance.
While your question is really more general (and only using
gccas an example), my first idea would be to usestraceto figure out what it’s doing. On my system (Ubuntu 11.10/x64), I just ranstrace, like so:This shows system calls for the
gccprocess, while following forks (-F) and sending the output of the trace tosout. Doing this, I can see thatgcchere callsvfork(), and thenexecve()in the child, though the actual program’s source might just do a simplefork()/exec().The relevant output from
soutis:At the begnning of each line is the pid of the process running. So the primary process calls
stat()to findcc1, then forks, and the child executes it.That being said, I could have answered your question without the citation; fork/exec is a common way to call sub-processes from your program.