Çok iş parçacıklı bir uygulamayı çatal etmeye çalıştım. Çatal ikinci iş parçamı çoğaltmıyor gibi görünüyor.Çatal komutu çok dişli bir uygulama ile çalışıyor mu?
#include <stdlib.h>
#include <pthread.h>
#include <iostream>
#include <linux/unistd.h>
#include <iostream>
#include <sys/types.h>
#include <sys/wait.h>
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
#include <string>
#include <unistd.h>
#include <stdlib.h>
#include <sys/ioctl.h>
using namespace std;
void Loop(const char* zThread)
{
while (true)
{
sleep(2);
cout << "LOOP : " << zThread << " : " << getpid() << endl;
}
}
void *MyFunction(void *pData)
{
Loop("Second");
};
int main()
{
pthread_t thread1;
pthread_create(&thread1, NULL, MyFunction, NULL);
int iPID = fork();
if (iPID == 0)
cout << "Child : " << getpid() << endl;
else
cout << "Parent : " << getpid() << endl;
Loop("First");
return EXIT_SUCCESS;
};
O çocuk sürecinin ikinci parçacığı tarafından yazılan herhangi bir bilgi içermiyor şu çıktıyı verir:
Bu
benim kodudur.test_1/ss> ./a.out
Parent : 11877
Child : 11879
LOOP : Second : 11877
LOOP : First : 11877
LOOP : First : 11879
LOOP : Second : 11877
LOOP : First : 11877
LOOP : First : 11879
LOOP : Second : 11877
LOOP : First : 11877
LOOP : First : 11879
LOOP : Second : 11877
LOOP : First : 11877
LOOP : First : 11879
LOOP : Second : 11877
LOOP : First : 11877
LOOP : First : 11879
LOOP : Second : 11877
LOOP : First : 11877
LOOP : First : 11879
İkinci konuya ne oldu? çatal denilen bir () -