- 论坛徽章:
- 0
|
- #include <time.h>
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <arpa/inet.h>
- #include <string.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <dirent.h>
- #include <sys/stat.h>
- #include <signal.h>
- #include <sys/wait.h>
- #include <pthread.h>
- #include <errno.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include <stropts.h>
- int fd[2];
- int
- s_pipe(int fd[2])
- {
- return(pipe(fd));
- }
- void child()
- {
- int sfd;
- if ((sfd = open("test.c", O_RDONLY)) < 0) {
- perror("open failed");
- exit(-1);
- }
- if (ioctl(fd[1], I_SENDFD, sfd) < 0) {
- perror("ioctl send failed");
- exit(-1);
- }
- close(sfd);
- exit(-1);
- }
- int main()
- {
- pid_t pid;
- if (s_pipe(fd) < 0) {
- perror("pipe failed");
- exit(-1);
- }
- if ((pid = fork()) < 0) {
- perror("fork error");
- exit(-1);
- }
- else if (pid == 0) { /* child */
- close(fd[0]);
- sleep(3);
- child();
- }
- else
- close(fd[1]); /* parent */
-
- struct strrecvfd recvfd;
- if (ioctl(fd[0], I_RECVFD, &recvfd) < 0) {
- perror("ioctl recv failed");
- return(-1);
- }
- int rfd = recvfd.fd;
- printf("rfd = %d\n", rfd);
-
- return 0;
- }
复制代码
我参考了UNIx环境高级编程里17.2,17.4,17.5,写出了上面的程序,但是运行时总是报:
ioctl recv failed: Invalid argument
ioctl send failed: Invalid argument
我看了半天也不知到是那个argument不对啊?麻烦各位帮我瞅瞅!
先谢过了! |
|