Linux Programming(2)

/***************************************************************************
 
    filename:    goout.c
 ***************************************************************************/

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
    int pid;
    int status;

    if((pid=fork())<0){
        printf("Fork error!n");
    }

    if(pid==0){    /* child */
        char avs[1][1];
        execv("/home/user/gogo/src/my.out",avs[1]);
        while(1);
        exit(0);
    }else{
        int ss=0;
        while(ss<10){
            printf("Father —  %dn",ss++);
            printf("Father & Mom: Father loves your mothern");
            sleep(1);
        }
        wait(&status);
        printf("Father exit normallyn");
    }        

    
  return EXIT_SUCCESS;
}

/******************************
filename: my.c
********************************/

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{   
        int s=0;
        while(s<10){
            printf("My.out: —  %dn",s++);
            sleep(1);
        }
  return EXIT_SUCCESS;
}

发表评论

邮箱地址不会被公开。 必填项已用*标注