【问题标题】:How to run ps for debugging multi-threaded program in linux?如何在linux中运行ps调试多线程程序?
【发布时间】: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


【解决方案1】:

要严格回答您的问题,一种方法是在同一窗口的不同终端中使用 tmux。尽可能多地打开,准备好你的命令,设置 tmux 以在 tmux 提示符下使用 :setw synchronize-panes on 复制输入,然后按回车键同时运行所有命令。这是它的样子:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多