pthread_create b/w fork and exec
pthread_create b/w fork and exec
我希望在子进程中创建一个线程,然后使用exec系统调用改变子进程的图像。然而,pthread_create调用似乎被忽略了。
pthread_t thread;
pthread_attr_t attribute;
pthread_attr_init(&attribute);
pthread_attr_setdetachstate(&attribute, PTHREAD_CREATE_DETACHED);
pid_t cid = fork();
if(cid == 0) //CHILD Process
{
switch(x->option)
{
case 1: pthread_create(&thread, &attribute, compressShow, NULL);
execl("/home/aamir/Lab/ass3/compression", "compression", source, destination, NULL);
cout<<"Execution failed."<<endl; break; //This segment will execute if exec fails.
}
else //PARENT Process
{
wait(0); //Prevents termination of original main until forked exec completes execution
pthread_cancel(thread);
}
线程基本上只是一个用于输出'的进度显示。'(点)与fork子进程并发。
如果我删除exec调用,线程将执行。我在谷歌上搜索过,读到你不能在fork和exec之间使用pthread_create,这与异步安全函数有关。你能帮帮我吗?
exec位删除所有内容,包括线程,然后启动一个新进程。这包括内存等
程序可能(通常)不会到达启动线程的位。
相关文章:
- C++核心准则 C35 对于接口类"A base class destructor should be either public and virtual, or protected and nonv
- 为什么C++逐位AND运算符在不同大小的操作数中表现为这样
- 为什么 Clang 不允许"and"作为函数名称?
- 位阵列上的快速AND运算
- 是否可以在 C++03 中定义'move-and-swap idiom'等效项
- BoostPython and CMake
- OpenSSL BIO and SSL_read
- execlp() 在 fork() 之后无法正常工作
- Gurobi GRBModel and GRBmodel in C++
- std::visit and std::variant usage
- 在 fork() 之后,我在我的程序中不断得到相同的 pid
- SHBrowseForFolder with BIF_BROWSEFORCOMPUTER and SHGetPathFr
- Directx12 and keystrokes
- C/C++ linux fork() and exec()
- C++, linux, fork, execvp, waitpid and SIGTSP
- Understanding fork, exec, and wait in C++ (Linux)
- fork and wait系统调用出现问题
- Fork() and Wait() in C++
- pthread_create b/w fork and exec
- fork exec and mmap issues