Hi all.
Sorry to express my questions wrongly in my early post,I repost my question again here.
My pc has dual core, I wirte an application with two process, parents process and child process.
My quetion is
how to realize :if the child process is on core 0,it will tell me I'm on core 0,if it is on core1, it will tell me I'm on core 1
I have do some try, if I just add "printf(my pid is %d on core %d,getpid(),sched_getcpu), it outpout just *one*states that which core it is on.you know child process is not just on core 0 or 1 one time.
How to realize above, do we need wrtie a monitor application, can some one give me an example?
Quote:
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int main ()
{
pid_t child_pid;
printf (“the main program process ID is %d\n”, (int) getpid ());
child_pid = fork ();
if (child_pid != 0) {
printf (“this is the parent process, with id %d\n”, (int) getpid ());
printf (“the child's process ID is %d\n”, (int) child_pid);
}
else
{
// child process , I want to mornitor which core it run on.
}
}