-2
Ich habe ein C++ - Programm, das Prozessthreads in LINUX erstellt. Wie kann ich diesen Code ändern, um unendlich viele Prozesse zu erstellen? Ich habe die Zählung zur Zeit auf 5 gesetzt Hier mein Code ist:Schreiben und Ausführen eines C- oder C++ - Programms, das eine unendliche Anzahl von Prozessen erstellt.
#include <iostream>
#include <cstdlib>
#include <pthread.h>
#include <stdint.h>
#include <inttypes.h>
using namespace std;
#define THREAD_COUNT 5
void *PrintPhrase(void *threadid)
{
long tid;
tid = (long)threadid;
cout << "THis Is A Great Day Thread ID, " << tid << endl;
pthread_exit(NULL);
}
int main()
{
pthread_t threads[THREAD_COUNT];
int rc;
uintptr_t i;
for(i=0; i < THREAD_COUNT; i++){
cout << "main() : creating thread, " << i << endl;
rc = pthread_create(&threads[i], NULL,
PrintPhrase, (void *)i);
if (rc){
cout << "Error:unable to create thread," << rc << endl;
exit(-1);
}
}
pthread_exit(NULL);
}
[ 'fork'] (http://man7.org/linux/ Man-Seiten/man2/fork.2.html)? – NathanOliver
Threads sind keine Prozesse, es gibt signifikante Unterschiede. –
Sie möchten also eine [Gabelbombe] (https://en.wikipedia.org/wiki/Fork_bomb) erstellen? Das wird deine Maschine so sehr zum Absturz bringen. Wenn Sie nicht 5 zu einer viel größeren Zahl allein ändern können, bin ich nicht sicher, was wir tun können, um zu helfen. – tadman