>>>Здравствуйте.
>>>Подскажите пожалуйста Кто знает как с помощью sysctl или kvm получить загруженность
>>>процессора и занятую определенными роцессами,
>> память
>>
>>Hi,
>>
>>Why do not you want to use "top" in batch mode?
>>
>>Thanks
>>--- sas
>Мне програмно на С нужно сделать
Hi,
If you want to do it in C you can use I think something like:
1) popen( "top b n 1 p your_pid_number", "r" ); and parse last line of the output in your code. Most portable and easy way.
2) Also you can parse /proc/YOUR_PID_NUMBER/status; /proc/YOUR_PID_NUMBER/stat; /proc/YOUR_PID_NUMBER/mem; /proc/YOUR_PID_NUMBER/environ and other files on linux and if i right on *bsd. Less portable and easy, because you have to open/close a lot of files :)
3) Most difficult, nonportable and insecure way: On linux you can use (on solaris/bsd as i know kvm_* functons family):
#include <linux/sched.h>
struct task_struct ts;
...
kmem = open( /dev/kmem, O_RDONLY );
lseek( kmem, offset_of_task_struct, SEEK_SET );
read( kmem, &ts, sizeof( ts ) );
...
/* read tasks using ts.next_task etc */
...
close( kmem );
The most difficult here is offset.
Hope it helps.
--- Sas