关于调用linux下的daemon函数出现的线程退出问题。

根根小盆友 根根小盆友 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
程序在前台跑正常,一切到后台,线程就退出了。不知道什么原因,求大神指导。。。

#include <stdio.h>
#include <pthread.h>

pthread_t tid;

void *fun()
{
FILE* pf = fopen("test", "ab");
while(1)
{
fprintf(pf, "aaaa\n");
sleep(5);
fflush(pf);
}
}

int aa()
{
pthread_create(&tid, NULL, fun, NULL);
}

int main()
{
aa();

//daemon注释打开线程就自动的退出了
//daemon(0,0);

pthread_join(tid, NULL);
}
...全文

相关推荐

评论 4
收藏 已收藏
分享
返回顶部
根根小盆友
C语言 70,040 成员 243,237 内容