nie*_*bot 10
你可以使用top
和刮掉你想要的东西,但我很好奇,所以我挖得更深一些,找到了/usr/include/libproc.h
,并写了一些代码:
#import <libproc.h>
#import <stdlib.h>
#import <stdio.h>
int main( int argc, const char * argv[])
{
pid_t * pids = calloc(0x1000, 1);
int count = proc_listallpids(pids, 0x1000);
printf("count=%u\n", count) ;
for( int index=0; index < count; ++index)
{
pid_t pid = pids[ index ] ;
struct proc_taskinfo taskInfo ;
/*int result*/ proc_pidinfo( pid, PROC_PIDTASKINFO, 0, & taskInfo, sizeof( taskInfo ) ) ;
// fields of taskInfo:
// uint64_t pti_virtual_size; /* virtual memory size (bytes) */
// uint64_t pti_resident_size; /* resident memory size (bytes) */
// uint64_t pti_total_user; /* total time */
// uint64_t pti_total_system;
// uint64_t pti_threads_user; /* existing threads only */
// uint64_t pti_threads_system;
// int32_t pti_policy; /* default policy for new threads */
// int32_t pti_faults; /* number of page faults */
// int32_t pti_pageins; /* number of actual pageins */
// int32_t pti_cow_faults; /* number of copy-on-write faults */
// int32_t pti_messages_sent; /* number of messages sent */
// int32_t pti_messages_received; /* number of messages received */
// int32_t pti_syscalls_mach; /* number of mach system calls */
// int32_t pti_syscalls_unix; /* number of unix system calls */
// int32_t pti_csw; /* number of context switches */
// int32_t pti_threadnum; /* number of threads in the task */
// int32_t pti_numrunning; /* number of running threads */
// int32_t pti_priority; /* task priority*/
printf("PID %u:\n", pid);
printf("\t%20s\t%u\n", "number of threads", taskInfo.pti_threadnum) ;
printf("\t%20s\t%u\n", "number running threads", taskInfo.pti_numrunning) ;
printf("\n") ;
}
return EXIT_SUCCESS ;
}
Run Code Online (Sandbox Code Playgroud)
小智 0
对于 Objective C,您可以使用NSTask进行系统调用来sysctl -aw
获取诸如
kern.maxproc = xxxx
kern.num_threads: xxxxx
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1508 次 |
最近记录: |