c++ - linux下如何运行ps调试多线程程序?

标签 c++ linux debugging shell pthreads

我有这段代码:

#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 键同时运行所有命令。它看起来像这样: tmux powah!

关于c++ - linux下如何运行ps调试多线程程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10471841/

相关文章:

c++ - pimpl idiom vs. bridge 设计模式

linux - 查找列是否在范围内

python - theano - TensorVariable 的打印值

c++ - 是否可以强制Linux在释放后使虚拟内存失效

c++ - nullptr 可以用作变量参数(varargs)吗?

c++ - C++ 模板如何专用于所有 32 位 POD 类型?

c++ - io_getevents 在短于超时的时间内返回的作业数量少于请求的数量

linux - bash with ssh 和 for i 语句

ios - 在 ios 上请求照片库权限导致 watchos 崩溃?

debugging - 您最喜欢的反调试技巧是什么?