// Return YES if given name process in process list . Otherwise return NO
bool 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];
if (strcmp(name, proc->kp_proc.p_comm) == 0) {
free(result);
return true;
}
}
}
free(result);
return false;
}
Just reformatted Haley's answer:
// Return YES if given name process in process list . Otherwise return NO
bool 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];
if (strcmp(name, proc->kp_proc.p_comm) == 0) {
free(result);
return true;
}
}
}
free(result);
return false;
}
发布评论
评论(3)
刚刚重新格式化了海莉的答案:
Just reformatted Haley's answer:
你的问题比较模糊。您能定义一下“获取流程”的含义吗?
一种方法(取决于您的定义):在“应用程序/实用程序”中启动“活动监视器”应用程序,然后在列表中查找进程名称。
Your question is rather vague. Can you define what you mean by "get a process"?
One method (depending on your definition): launch the Activity Monitor app in Applications/Utilities, and look up the process name in the list.
也许
来自控制台
Perhaps
from a console