05-17-2004 11:31 PM
I am using VTune 2.0. I used the sampling collector to analyze one of my application. In the result (I used the process view), I saw two processes with the same PID. One of them is my application, and the other is vtl.bin. Why they can have the same PID?
05-21-2004 06:44 PM
Glad you spoke up here.
Sounds like you know already that two processes can't have the same process ID in the process run table in the kernel. Exactly right!
As it turns out, in Linux, a parent process can spawn children a couple of ways. If it forks() them, the child will have a new, higher PID. If the parent execs() the child, it's really not a child per se,but the same process, and therefore, the child will have the same PID as the parent process.
Even at the command line, at say a bash prompt, you can simulate this condition.
1) login and type pwd:
You'll get the directory you're in of course, and another shell prompt, like I've simulated above.
What happens there is, the bash shell reads my command (pwd) after I press enter, forks() a child process which is an exact duplicate of itself (bash) in every way, except for the PID which is higher, then, and this is the point, the CHILD process runs the pwd, which happens to be a built in command to the shell. The parent bash that forked() the child is now pause(), waiting for an exit code from the child before doing anything else.
The CHILD exits, and the parent bash sees the exit code, in this case success from the pwd command, and stops pausing, then giving you as it's supposed to another prompt, "READY FOR THE NEXT COMMAND."
2) to force an exec() instead, which will mean, do the command yourself bash, don't fork a child to do it, actually run an exec with the command:
$ exec pwd
Because this instructs the parent bash to run pwd, you'll run the command but there won't be any parent to take over again. YOU WILL BE LOGGED OFF!
Try it. Totally cool
So, in your example, vtl.bin exec'd your application. Same process, same process ID.
Play around with this stuff: you'll like it!
PS: You may be familiar with the use of the ampersand (&) in the linux command line of most shells, which is known as background execution? Really in the case of bash shell, putting a command in the background means telling the parent not to pause(), that is, not to wait for an exit status from the spawned child process from the fork(). EASY PEASY!!