Changeset 2278


Ignore:
Timestamp:
Aug 14, 2005, 8:42:50 AM (20 years ago)
Author:
bird
Message:

..

Location:
trunk/src/libctests/libc/smoketests
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/libctests/libc/smoketests/fork-1.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r2277 r2278  
    77 *
    88 *
    9  * This file is part of kBuild.
     9 * This file is part of InnoTek LIBC.
    1010 *
    11  * kBuild is free software; you can redistribute it and/or modify
     11 * InnoTek LIBC is free software; you can redistribute it and/or modify
    1212 * it under the terms of the GNU General Public License as published by
    1313 * the Free Software Foundation; either version 2 of the License, or
    1414 * (at your option) any later version.
    1515 *
    16  * kBuild is distributed in the hope that it will be useful,
     16 * InnoTek LIBC is distributed in the hope that it will be useful,
    1717 * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1818 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     
    2020 *
    2121 * You should have received a copy of the GNU General Public License
    22  * along with kBuild; if not, write to the Free Software
     22 * along with InnoTek LIBC; if not, write to the Free Software
    2323 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    2424 *
  • trunk/src/libctests/libc/smoketests/fork-exec-1.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.2
    r2277 r2278  
    4343{
    4444    if (argc == 2 && !strcmp(argv[1], "child"))
     45    {
     46        printf("fork-exec-1: %d: child of %d\n", getpid(), getppid());
    4547        return 0;
     48    }
     49    printf("fork-exec-1: %d: %s, parent %d\n", getpid(), argc >= 2 ? argv[1] : "main", getppid());
    4650
    4751    char *argv_child[3];
     
    4953    argv_child[1] = "child";
    5054    argv_child[2] = NULL;
    51     int rc = spawnvp(P_WAIT, argv_child[0], argv_child);
    52     if (rc)
     55    if (argc != 2 || strcmp(argv[1], "2nd"))
    5356    {
    54         printf("fork-exec-1: child1 failed! rc=%d\n", rc);
    55         return 1;
     57        int rc = spawnvp(P_WAIT, argv_child[0], argv_child);
     58        if (rc)
     59        {
     60            printf("fork-exec-1: child1 failed! rc=%d\n", rc);
     61            return 1;
     62        }
    5663    }
    5764
    5865    /*
    59      * Main process.
     66     * Fork children (three generations).
    6067     */
    6168    pid_t pid = fork();
     
    6774    if (pid == 0)
    6875    {
    69         execvp(argv_child[0], argv_child);
     76        if (argc == 2 && !strcmp(argv[1], "1st"))
     77        {
     78            printf("fork-exec-1: %d: 2nd fork, from %d\n", getpid(), getppid());
     79            argv_child[1] = "2nd";
     80            execvp(argv_child[0], argv_child);
     81        }
     82        else if (argc != 2 || strcmp(argv[1], "2nd"))
     83        {
     84            printf("fork-exec-1: %d: 1st fork, from %d\n", getpid(), getppid());
     85            argv_child[1] = "1st";
     86            execvp(argv_child[0], argv_child);
     87        }
     88        else
     89        {
     90            printf("fork-exec-1: %d: 3rd fork, from %d\n", getpid(), getppid());
     91            execvp(argv_child[0], argv_child);
     92        }
    7093        printf("fork-exec-1: exec failed! errno=%d %m\n", errno);
    7194        return 1;
Note: See TracChangeset for help on using the changeset viewer.