how to monitor the child process on which cpu core


 
Thread Tools Search this Thread
Top Forums Programming how to monitor the child process on which cpu core
# 1  
Old 06-28-2009
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  
Old 06-30-2009
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Monitor the CPU load for each process and total

Hi guys, I have to set up a script which monitors the amount of AVG CPU load per each process and also the total load for a sum of processes. The processes have the same name, I can only differentiate by port number they listen to, as follows : 28171 root 20 0 1089m 21m 3608 S 103... (1 Reply)
Discussion started by: liviusbr
1 Replies

2. Shell Programming and Scripting

Shell script to monitor process with high CPU

Hi, Linux redhat 5.5 I need to write a kshell script that shows all the process that consume 100% CPU (or more. strange but there are time that top shows higger value that 100) and they are active more than 5 minute. The top command shows all the relevat information: The PID of the cpu ,... (0 Replies)
Discussion started by: yoavbe
0 Replies

3. UNIX for Dummies Questions & Answers

How to monitor per core CPU utilization?

I can use top to see the overall cpu utilization in the system but i m using a system with 24 cores .How would i monitor each core utilization ? The system is used as Oracle VM Server for Virtualization. My distribution details. # lsb_release -a LSB Version: ... (8 Replies)
Discussion started by: pinga123
8 Replies

4. Shell Programming and Scripting

forking a child process and kill its parent to show that child process has init() as its parent

Hi everyone i am very new to linux , working on bash shell. I am trying to solve the given problem 1. Create a process and then create children using fork 2. Check the Status of the application for successful running. 3. Kill all the process(threads) except parent and first child... (2 Replies)
Discussion started by: vizz_k
2 Replies

5. Emergency UNIX and Linux Support

signal between parent process and child process

Hello, everyone. Here's a program: pid_t pid = fork(); if (0 == pid) // child process { execvp ...; } I send a signal (such as SIGINT) to the parent process, the child process receive the signal as well as the parent process. However I don't want to child process to receive the... (7 Replies)
Discussion started by: jackliang
7 Replies

6. Shell Programming and Scripting

script to monitor the process system when a process from user takes longer than 15 min run.

get email notification from from system when a process from XXXX user takes longer than 15 min run.Let me know the time estimation for the same. hi ,any one please tell me , how to write a script to get email notification from system when a process from as mentioned above a xxxx user takes... (1 Reply)
Discussion started by: kirankrishna3
1 Replies

7. Shell Programming and Scripting

[KSH/Bash] Starting a parent process from a child process?

Hey all, I need to launch a script from within 2 other scripts that can run independently of the two parent scripts... Im having a hard time doing this, if anyone knows how please let me know. More detail. ScriptA (bash), ScriptB (ksh), ScriptC (bash) ScriptA, launches ScriptB ScirptB,... (7 Replies)
Discussion started by: trey85stang
7 Replies

8. Shell Programming and Scripting

How to make the parent process to wait for the child process

Hi All, I have two ksh script. 1st script calls the 2nd script and the second script calls an 'C' program. I want 1st script to wait until the 'C' program completes. I cant able to get the process id for the 'C' program (child process) to make the 1st script to wait for the second... (7 Replies)
Discussion started by: sennidurai
7 Replies

9. Shell Programming and Scripting

script to monitor process running on server and posting a mail if any process is dead

Hello all, I would be happy if any one could help me with a shell script that would determine all the processes running on a Unix server and post a mail if any of the process is not running or aborted. Thanks in advance Regards, pradeep kulkarni. :mad: (13 Replies)
Discussion started by: pradeepmacha
13 Replies

10. UNIX for Dummies Questions & Answers

how to get persistant cpu utilization values per process per cpu in linux (! top,ps)

hi, i want to know cpu utilizatiion per process per cpu..for single processor also if multicore in linux ..to use these values in shell script to kill processes exceeding cpu utilization.ps (pcpu) command does not give exact values..top does not give persistant values..psstat,vmstat..does njot... (3 Replies)
Discussion started by: pankajd
3 Replies
Login or Register to Ask a Question