Exemplo n.º 1
0
void  main(void)
{
     pid_t   pid1, pid2, pid;
     int     status;
     int     i;
     char    buf[BUF_SIZE];
     
     printf("*** Parent is about to fork process 1 ***\n");
     if ((pid1 = fork()) < 0) {
          printf("Failed to fork process 1\n");
          exit(1);
     }
     else if (pid1 == 0) 
          ChildProcess("First", "   ");

     printf("*** Parent is about to fork process 2 ***\n");
     if ((pid2 = fork()) < 0) {
          printf("Failed to fork process 2\n");
          exit(1);
     }
     else if (pid2 == 0) 
          ChildProcess("Second", "      ");

     ParentProcess();
     sprintf(buf, "*** Parent enters waiting status .....\n");
     write(1, buf, strlen(buf));
     pid = wait(&status);
     sprintf(buf, "*** Parent detects process %d was done ***\n", pid);
     write(1, buf, strlen(buf));
     pid = wait(&status);
     printf("*** Parent detects process %d is done ***\n", pid);
     printf("*** Parent exits ***\n");
     exit(0);
}
Exemplo n.º 2
0
void  main(void)
{
     pid_t  pid;

     pid = fork();
     if (pid == 0)
          ChildProcess();
     else
          ParentProcess();
}
Exemplo n.º 3
0
void  main(void)
{
     pid_t  pid;

     pid = fork();
	 if (pid == -1)
        {
            printf ("Can't fork!!\n"); //обработчик ошибок при вызове fork
            exit (-1);
        }
     else if (pid == 0) 
          ChildProcess();
     else 
          ParentProcess();
}
Exemplo n.º 4
0
int main()
{
    int status;
    pid_t pid;
    
    mem_alloc = (int*) malloc(sizeof(int));
    *mem_alloc = 1000;

    pid = fork();
    
    if (pid == 0)
        ChildProcess();
    else
        ParentProcess();

    wait(&status);
    return 0;
}