[M1 Mac, Monterey 12.6.3, clang 13.0.0, FLTK 1.3.8, ChatGPT Plus, NO IDE]
マルチスレッドの次はマルチプロセスです。
fork関数を使って別のプロセスIDを作成しましたが、プログラムはそこで停止しました。
CoreFoundationはfork()をサポートしていないそうです。POSIX標準なのでLinuxでのみ使用可能とのこと。
void processA() {
std::cout << "ProcessA: PID = " << getpid() << std::endl;
sendCB_A();
}
void processB() {
std::cout << "ProcessB: PID = " << getpid() << std::endl;
timerCallback(nullptr);
}
void sendCB(Fl_Widget*, void*) {
sendBool = true;
pid_t pidA, pidB;
pidA = fork();
if (pidA == 0) { // 子プロセスA
processA();
return;
}
else if (pidA > 0) { // 親プロセス
std::cout << "Parent process: PID = " << getpid() << std::endl;
pidB = fork();
if (pidB == 0) { // 子プロセスB
processB();
return;
}
else if (pidB > 0) { // 親プロセス
waitpid(pidA, NULL, 0);
waitpid(pidB, NULL, 0);
}
else { // forkに失敗した場合
std::cerr << "fork() failed." << std::endl;
return;
}
}
else { // forkに失敗した場合
std::cerr << "fork() failed." << std::endl;
return;
}
}
Parent process: PID = 62590
ProcessA: PID = 62601
question1回目
ChatGPTとは
requestData: {"model":"gpt-3.5-turbo", "messages":[{"role":"system","content":""},{"role":"user","content":"ChatGPTとは"}], "temperature":0.0}
ProcessB: PID = 62602
The process has forked and you cannot use this CoreFoundation functionality safely. You MUST exec().
Break on __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__() to debug.
The process has forked and you cannot use this CoreFoundation functionality safely. You MUST exec().
Break on __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__() to debug.
The process has forked and you cannot use this CoreFoundation functionality safely. You MUST exec().