fork,在子进程中重定向输入,然后执行shell程序
- /* create a new process or quit */
- if( (pid = fork() ) == -1 )
- oops("fork", 1);
- /* child does the work */
- if ( pid == 0 ){
- /* close then open */
- close(0);
- if ( open(file,O_RDONLY) != 0 )
- oops(file,2);
- execlp( "sort", "sort", NULL ); /* and run */
- oops("sort",3);
- }
- /* parent waits then reports */
- if ( pid != 0 ){
- wait(NULL);
- printf("Done running sort < %s\n", file);
- }
阅读(1538) | 评论(0) | 转发(0) |