私はこのコードを持っています:
#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);
}
ps -Lf, ps -T, ps -Lm
シェルから上記のコードと同時に実行するにはどうすればよいですか? シェルコマンドプロンプトで両方を実行するにはどうすればよいですか? 別のタブを使用しても正しく動作しないようです。