Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I build my RTAI-model-source(generated by simulink) in CygWin with gcc-linux-4.1 (cross-compiler of CygWin) on Windows, and generate ELF successfully. and the ELF runs correctly on Ubuntu.

After the ELF is running correctly on Ubuntu, there are four processes with the same name but different process-id in the system monitor.

But if I build my source with gcc on Linux, it generates only 1 process, so I think fork() or exec() may not be called.

How can one exec file make four processes?

The ps -elF shows:

4 S root      3679  3314  0  57   - -  4362 hrtime 17:44 pts/1    00:00:00 /root/Test/test
5 S root      3680  3679  0  57   - -  4362 poll_s 17:44 pts/1    00:00:00 /root/Test/test
5 S root      3681  3680  0  56   - -  4362 rt_sch 17:44 pts/1    00:00:00 /root/Test/test
5 S root      3682  3680  0 -40   - -  4362 rt_sch 17:44 pts/1    00:00:00 /root/Test/test
share|improve this question

closed as too localized by psusi, vonbrand, Anthon, Hauke Laging, slm May 30 '13 at 20:28

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

It's possible that GCC compiling for Windows does multi-threading where compiling for native linux execution does fork/exec. Or maybe I misunderstand where the two executables run. – Bruce Ediger May 30 '13 at 12:51
The two executables run on Ubuntu, the cross-compiled one generate 4 processes and the native generate 1 process. – YangH May 30 '13 at 14:20

It's perfectly normal for certain processes to create other copies of themselves after execution, usually to improve performance through parallel execution. As for how it works, the process fork(2)'s (it may or may not also exec(2) another copy of itself, depending on the way it is implemented). See man 2 fork and man 2 exec.

Essentially, new processes in Linux are first created as copies of the program calling them using fork(2). After that, they may replace their process image by using exec(2). This is the usual workflow when using, for example, a shell to execute commands. If it is the same process, there may be no subsequent exec -- it's also possible to have code executed that is conditional upon being in a certain child without having to exec.

Cambridge University has a good page on how this works if you want more information.

share|improve this answer
thanks, i know the fork() and exec(), but i build my source on linux, and it generate only 1 process, so i think fork() or exec() may not be called. – YangH May 30 '13 at 9:54

Not the answer you're looking for? Browse other questions tagged or ask your own question.