簡體   English   中英

如何運行ps來調試linux中的多線程程序?

[英]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鍵同時運行所有命令。 這是它的樣子: tmux powah!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM