|
就这个程序,运行后终端不会出现“lucifer@cross:~/C$“这个字符串的,但是输入的命令却照样执行。gdb说这个程序结束正常,开头也同样没有出现“(gdb)”字串。
这是怎么回事?
- lucifer@cross:~/C$ cat mkfifo.c
- /* 建立命名管道 */
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #define FIFO "/tmp/fifo"
- int
- main()
- {
- char buffer[80];
- int fd;
- unlink(FIFO);
- mkfifo(FIFO, 0666);
- if(fork() > 0)
- {
- char s[] = "Hello World!\n";
- fd = open(FIFO, O_WRONLY);
- write(fd, s, sizeof(s));
- close(fd);
- }
- else
- {
- fd = open(FIFO, O_RDONLY);
- read(fd, buffer, 80);
- printf("%s", buffer);
- close(fd);
- }
- return 0;
- }
- lucifer@cross:~/C$ ./a.out
- lucifer@cross:~/C$ Hello World!
- sudo fdisk -l
- [sudo] password for lucifer:
- Disk /dev/sda: 250.1 GB, 250059350016 bytes
- 255 heads, 63 sectors/track, 30401 cylinders
- Units = cylinders of 16065 * 512 = 8225280 bytes
- Sector size (logical/physical): 512 bytes / 512 bytes
- I/O size (minimum/optimal): 512 bytes / 512 bytes
- Disk identifier: 0x7b8466c5
- Device Boot Start End Blocks Id System
- /dev/sda1 * 1 3825 30724281 7 HPFS/NTFS
- /dev/sda2 3826 27726 191984393 5 Extended
- Partition 2 does not end on cylinder boundary.
- /dev/sda4 27727 30401 21486937+ 7 HPFS/NTFS
- /dev/sda5 3826 3837 96358+ 83 Linux
- /dev/sda6 3838 4335 4000153+ 82 Linux swap / Solaris
- /dev/sda7 4336 6563 17896378+ 83 Linux
- /dev/sda8 6564 10327 30233600 7 HPFS/NTFS
- /dev/sda9 10328 12817 19998720 83 Linux
- /dev/sda10 12817 19664 54999040 83 Linux
- /dev/sda11 19665 22154 19998720 83 Linux
- /dev/sda12 22154 24644 19998720 83 Linux
- /dev/sda13 24644 27726 24757248 83 Linux
- lucifer@cross:~/C$
复制代码 |
|