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



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
script to monitor process running on server and posting a mail if any process is dead pradeepmacha Shell Programming and Scripting 13 03-06-2009 07:33 AM
Can a child process return a specific value to a parent process ? Ametis1970 High Level Programming 8 04-09-2008 11:22 PM
fedora core 6 not supported for acer lcd monitor nageshrk Linux 1 08-19-2007 05:18 AM
gdb to child process shriashishpatil UNIX for Advanced & Expert Users 4 12-12-2005 07:57 AM
KDM child process larryase UNIX for Dummies Questions & Answers 6 01-24-2005 05:41 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #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.
}
}
  #2 (permalink)  
Old 06-30-2009
otheus's Avatar
otheus otheus is offline Forum Staff  
Moderator ala Mode
  
 

Join Date: Feb 2007
Location: Innsbruck, Austria
Posts: 1,864
Did you mention what OS? If Linux, you can look at /proc/self/stat and depending on the version of your kernel, one of the fields will represent the processor most recently executed on. You can look at the manpage for "proc" to find out which field. You can get the parent id of the process using getppid() and look in /proc/$PPID/stat for the same info.
Sponsored Links
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 08:55 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0