Determine Process Info Programmatically in Darwin/OSX

前端 未结 5 411
无人及你
无人及你 2020-11-28 11:26

I have a class with the following member functions:


/// caller pid
virtual pid_t Pid() const = 0; 

/// physical memory size in KB
virtual uint64_t Size() c         


        
5条回答
  •  孤城傲影
    2020-11-28 12:03

    You can use below code for process info in mac OS:

    void IsInBSDProcessList(char *name)    { 
      assert( name != NULL); 
      kinfo_proc *result; 
      size_t count = 0; 
      result = (kinfo_proc *)malloc(sizeof(kinfo_proc)); 
      if(GetBSDProcessList(&result,&count) == 0) { 
        for (int i = 0; i < count; i++) { 
          kinfo_proc *proc = NULL; 
          proc = &result[i]; 
          }
      } 
      free(result);
    }
    

    kinfo_proc struct contains all the information about a process.such as Process identifier (pid), process group, process status and etc.

提交回复
热议问题