简体   繁体   中英

How to run ps for debugging multi-threaded program in linux?

I have this code :

#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);
}

How can I run from shell the ps -Lf, ps -T, ps -Lm simultaneously to the code above? I mean how can I run both in the shell command prompt? using another Tab doesn't seem to work properly.

To strictly answer your question, one way to do it is with tmux , in separate terminals in the same window. Open as many as necessary, prep your commands, set tmux to duplicate the input with :setw synchronize-panes on at the tmux prompt, and then hit enter to run all the commands simultaneously. Here's how it would look like: tmux powah!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM