如果一个程序本身是多线程的程序,那么在其中的一个线程里进行fork操作,他的子进程是个单线程的进程还是个多线程的进程呢?
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/syscall.h>
#include <pthread.h>
#include <thread>
#include <unistd.h>
using namespace std;
pid_t gettid()
{
return syscall(SYS_gettid);
}
void t_func(void *arg)
{//父进程创建的线程
printf("pid:%u create thread:%d, id:%u\n", getpid(), *(int*)arg, gettid());
sleep(15);
printf("pid:%u exit thread:%d, id:%u\n", getpid(), *(int*)arg, gettid());
}
int main()
{
int i = 1;
printf("parent pid:%u\n", getpid());
thread t1(t_func, &i);
sleep(1);
pid_t pid = fork();
if(pid