On Wed, Jan 13, 2010 at 2:07 AM, Sebastian Spies
<[email protected]> wrote:
[dd]
> Could you
> please comment on the following code?
>
> int main(int argc, char** argv)
> {
> kvm_t *kd;
> struct kinfo_proc2 *info;
> int cnt;
>
> if(argc != 2)
> {
> printf("Please provide pid\n");
> exit(1);
> }
>
>
> kd = kvm_open(NULL, NULL, NULL, KVM_NO_FILES, "error");
> if(!kd)
> exit(1);
>
> if(cnt != 1)
Not related to what you are asking about, but, you are checking cnt
before it is set.
> {
> printf("No process found\n");
> exit(1);
> }
>
> info = kvm_getproc2(kd, KERN_PROC_PID, atoi(argv[1]),
> sizeof(struct kinfo_proc2), &cnt);
>
> printf("%x\n",(double)info->p_cpticks);
>
> exit(0);
> }