昆哥吧 关注:15贴子:242
  • 5回复贴,共1

我的材料

收藏回复

  • 61.157.97.*
Before:my pid is 23690
After:my pid is 23690, fork() said 23691[root@localhost root]# After:my pid is 23691, fork() said 0


1楼2007-10-08 10:42回复
    • 61.157.97.*
    ***About to exec ls –l ***ls is done .bye[root@localhost root]#
    [root@localhost root]# ./execdemo
    ***About to exec ls –l ***ls is done .bye[root@localhost root]#


    2楼2007-10-08 10:49
    回复
      • 61.157.97.*
      1楼中After之所以有两遍是因为父进程和子进程运行的原故!


      3楼2007-10-08 11:14
      回复
        • 61.157.97.*
        总用量 512
        -rw-r--r-- 1 root root 1155 7月 16 00:18 anaconda-ks.cfg
        -rwxr-xr-x 1 root root 12128 10月 8 09:24 a.out
        -rwxr-xr-x 1 root root 15963 10月 8 10:49 execdemo
        -rw-r--r-- 1 root root 199 10月 8 10:48 execdemo.c
        -rwxr-xr-x 1 root root 25200 10月 8 09:27 feew
        -rw-r--r-- 1 root root 341 10月 8 09:24 feew.c
        -rwxr-xr-x 1 root root 16292 10月 8 11:04 forkdemo
        -rw-r--r-- 1 root root 241 10月 8 11:04 forkdemo.c
        -rw-r--r-- 1 root root 23799 7月 16 00:17 install.log
        -rw-r--r-- 1 root root 3053 7月 16 00:17 install.log.syslog
        -rwxr-xr-x 1 root root 300032 9月 10 10:05 linux系统及程序设计实验指导书-终验稿.doc
        -rwxr-xr-x 1 root root 22377 10月 8 10:02 list
        -rw-r--r-- 1 root root 2401 10月 8 10:02 list.c
        -rw-r--r-- 1 root root 2886 10月 8 09:52 listm
        -rwxr-xr-x 1 root root 28703 10月 8 10:05 lists
        -rw-r--r-- 1 root root 2888 10月 8 10:05 lists.c
        -rw-r--r-- 1 root root 2886 10月 8 09:58 llls.c
        lrwxrwxrwx 1 root root 5 10月 8 08:09 root -> /root
        -rwxr-xr-x 1 root root 15950 10月 8 11:28 sss
        -rw-r--r-- 1 root root 198 10月 8 11:27 sss.c
        -rw-r--r-- 1 root root 593 10月 8 11:03 waitdemo.c


        4楼2007-10-08 11:27
        回复
          • 61.157.97.*
          #include<unistd.h> /* pipe() */
          #include<stdio.h>
          #include<sys/types.h> /* pid_t */
          #define MAXLINE 4096

          int main(void)
          {
          int n;
          int fd[2];
          pid_t pid;
          char line[MAXLINE];
          //创建管道
          if(pipe(fd)<0)
          printf("pipe error\n");
          //创建子进程
          if((pid=fork())<0)
          printf("fork error\n");
          else if(pid>0) /* parent*/
          {
           close(fd[0]);
           write(fd[1], "ls -l", 6);
          }else /* child*/
          {
           n = read(fd[0], line, MAXLINE);
           if (line[strlen(line)-1] == '\n')
           line[strlen(line)-1] = '\0';
           system(line);
          }


          5楼2007-10-22 09:46
          回复
            • 61.157.97.*
            [root@localhost root]# vi bbb.c
            [root@localhost root]# gcc -g bbb.c -o bbb
            [root@localhost root]# ./bbb
            Preparing for reading bytes... ...
            read sss from FIFO_SERVER
            read laji from FIFO_SERVER
            read lajiyangkun from FIFO_SERVER
             


            [root@localhost root]# ./bba
            Please send something
            [root@localhost root]# sss
            bash: sss: command not found
            [root@localhost root]# ./bba sss
            write sss to FIFO
            [root@localhost root]# ./bba laji yangku
            write laji to FIFO
            [root@localhost root]# ./bba lajiyangkun
            write lajiyangkun to FIFO
            [root@localhost root]#


            6楼2007-10-22 11:30
            回复