我有这段代码:
#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 命令提示符下同时运行它们?使用另一个选项卡似乎无法正常工作。
最佳答案
要严格回答您的问题,一种方法是使用 tmux ,在同一窗口的不同终端中。根据需要打开尽可能多的命令,准备命令,在 tmux 提示符下使用 :setw synchronize-panes on 将 tmux 设置为复制输入,然后按 Enter 键同时运行所有命令。它看起来像这样:
关于c++ - linux下如何运行ps调试多线程程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10471841/