Click here to Skip to main content
15,894,896 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I need to implement a program in C to record all tasks done by process from starting to termination using Linux Environment(Cantos).

This program should give me the PID of the process and all the corresponding states of this process as it run for e.g running, sleeping, waiting, block and termination along with the total memory and CPU usage in each state.
Posted
Updated 5-May-15 15:24pm
v2
Comments
Sergey Alexandrovich Kryukov 5-May-15 21:30pm    
Define "task"...
What have you tried so far?
—SA
[no name] 5-May-15 21:32pm    
Good story, what's your plan?
zahoorsaleem 5-May-15 21:40pm    
I have use task_struct structure but unable to get solution
[no name] 5-May-15 22:01pm    
You seem to be asking for code without making any effort yourself. This is the wrong place. Do your own work and get help when you face a real obstacle i.e. when you have a specific question.

You can use top cammand to get process status:
suppose pid to be monitered is 16452
CSS
top -p 16452 -b | grep PID -A1
  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
16452 ashish    20   0  702608 189280  92164 S   0.0  2.3   2:55.74 chrome
--
  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
16452 ashish    20   0  702608 189280  92164 S   0.3  2.3   2:55.75 chrome
--
 
Share this answer
 
Comments
Ashish Tyagi 40 2-Jun-16 0:44am    
Wow, someone down-voted all answers here but doesn't have guts to explain why.
As suggested you may retrieve some average values (based on kernel indicators) but, at least in my opinion, you cannot track all the process state changes, this info is only available to the process scheduler.
 
Share this answer
 
After so many suggestions it seems more or less legal to suggest you to get the sources of *NIX command 'ps' that you can find here[^].
It seems to be exactly what you are looking for ;) ...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900