[英]How to run ps for debugging multi-threaded program in linux?
我有這個代碼:
#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以復制輸入:在tmux提示符下設置setw synchronize- panes,然后按Enter鍵同時運行所有命令。 這是它的樣子:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.