【发布时间】:2015-12-11 23:22:46
【问题描述】:
以下代码:
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int main()
{
pid_t mypid = getpid();
write(1, &mypid, sizeof(pid_t));
return 0;
}
打印乱码而不是实际的 pid。为什么?
【问题讨论】:
-
因为您没有向
stdout发送文本。write是二进制输出函数。试试printf()。
标签: c unbuffered-output