|
发表于 2022-6-7 14:54:56
6328 浏览 0 回复
多线程printf日志无法通过>重定向输出
如下程序,gcc demo.c -o demo -lpthread 编译后,./demo > demo.txt ,,printf打印的内容无法写到demo.txt中
void *testThread(void *arg)
{
while(1)
{
printf("this is testThread\n");
sleep(1);
}
}
int main()
{
pthread_t pth;
pthread_create(&pth,NULL,testThread,NULL);
pthread_detach(pth);
while(1)
{
printf("this is main\n");
sleep(1);
}
}
|
|
|
|
|
|
|
登录或注册
扫一扫关注迅为公众号
|