The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 06-28-2009
yanglei_fage yanglei_fage is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 25
how to monitor the child process on which cpu core

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.
}
}