【发布时间】:2012-05-06 15:42:29
【问题描述】:
我有这个代码:
#include <iostream>
#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>
using namespace std;
void* printHello (void* threadId){
cout << "in print Hello"<< (long) threadId << endl;
pthread_exit(NULL);
}
#define num 1000000
int main () {
pthread_t threads [num];
int rc;
long t;
for (t=0 ; t<num; ++t){
cout <<"in main" << "thread Id = " << t << endl;
rc = pthread_create(&threads[t] , NULL , printHello , (void*)t);
if (rc) {
cout << "ERROR"<< "rc= "<< rc << endl;
exit(-1);
}
}
pthread_exit(NULL);
}
如何从 shell 中同时运行 ps -Lf, ps -T, ps -Lm 到上面的代码?
我的意思是如何在 shell 命令提示符下运行两者?使用另一个选项卡似乎无法正常工作。
【问题讨论】:
-
“同时”是指同时启动,还是同时启动?
-
我的意思是两者:或者同时启动,或者同时运行。
-
同时启动两个命令的典型方式是使用“command1 & command2”。
-
你为什么要创建一百万个线程?
-
如果您使用
ps解释您想要查看的内容或尝试调试的内容,也许会有所帮助
标签: c++ linux debugging shell pthreads