Tag: 多进程

fgets()调用重定向获取exception数据流

我正打算用C语言编写一个shell。 以下是源代码: #include #include #include #include #include int getcmd(char *buf, int nbuf) { memset(buf, 0, nbuf); fgets(buf, nbuf, stdin); printf(“pid: %d, ppid: %d\n”, getpid(), getppid()); printf(“buf: %s”, buf); if(buf[0] == 0) {// EOF printf(“end of getcmd\n”); return -1; } return 0; } int main(void) { static char buf[100]; int fd, r, ret; // Read and […]