bool GetLocalProgramName(char* processname)
{
char processdir[1024] = {0}
char* path_end
size_t len = 1024
bool ret = false
do
{
if(readlink("/proc/self/exe", processdir,len) <=0)
{
fprintf(stderr, "[ERROR]can not get process name\n")
break
}
path_end = strrchr(processdir, '/') // 进程目录
if(path_end == NULL)
{
fprintf(stderr, "[ERROR]can not parse process name\n")
break
}
++path_end
*path_end = '\0'
strcpy(processname, path_end)
ret = true
}while(0)
return ret
}
这是我以前的代码,稍微改造一下就行。
用命令的方式也是很方便将结果存到变量里呀,用一个复制或者重定向就行了。c代码:
#include <pthread.h>
#include <stdio.h>
void* print_xs (void* unused)
{
while (1)
fputc (‘x’, stderr)
return NULL
}
/* The main program. */
int main ()
{
int i=0
while(1){
pthread_t thread_id
if( NULL != pthread_create (&thread_id, NULL, &print_xs, NULL)){
break
}
i++
}
printf("创建线程个数:%d\n",i)
return 0
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)