{
    "mode": "man",
    "parameter": "fork",
    "section": "3am",
    "url": "https://www.chedong.com/phpMan.php/man/fork/3am/json",
    "generated": "2026-09-09T17:38:11Z",
    "synopsis": "@load \"fork\"\npid = fork()\nret = waitpid(pid)\nret = wait();",
    "sections": {
        "NAME": {
            "content": "fork, wait, waitpid - basic process management\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "@load \"fork\"\n\npid = fork()\n\nret = waitpid(pid)\n\nret = wait();\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "The fork extension adds three functions, as follows.\n\nfork() This function creates a new process. The return value is the zero in the child and the\nprocess-id  number  of  the child in the parent, or -1 upon error. In the latter case,\nERRNO indicates the problem.  In the child, PROCINFO[\"pid\"] and  PROCINFO[\"ppid\"]  are\nupdated to reflect the correct values.\n",
            "subsections": [
                {
                    "name": "waitpid()",
                    "content": "This  function  takes a numeric argument, which is the process-id to wait for. The re‐\nturn value is that of the waitpid(2) system call.\n\nwait() This function waits for the first child to die.  The  return  value  is  that  of  the\nwait(2) system call.\n"
                }
            ]
        },
        "BUGS": {
            "content": "There is no corresponding exec() function.\n\nThe  interfaces could be enhanced to provide more facilities, including pulling out the vari‐\nous bits of the return status.\n",
            "subsections": []
        },
        "EXAMPLE": {
            "content": "@load \"fork\"\n...\nif ((pid = fork()) == 0)\nprint \"hello from the child\"\nelse\nprint \"hello from the parent\"\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "GAWK: Effective AWK Programming,  filefuncs(3am),  fnmatch(3am),  inplace(3am),  ordchr(3am),\nreaddir(3am), readfile(3am), revoutput(3am), rwarray(3am), time(3am).\n\nfork(2), wait(2), waitpid(2).\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Arnold Robbins, arnold@skeeve.com.\n",
            "subsections": []
        },
        "COPYING PERMISSIONS": {
            "content": "Copyright © 2012, 2013, 2018, Free Software Foundation, Inc.\n\nPermission is granted to make and distribute verbatim copies of this manual page provided the\ncopyright notice and this permission notice are preserved on all copies.\n\nPermission  is granted to copy and distribute modified versions of this manual page under the\nconditions for verbatim copying, provided that the entire resulting derived work is  distrib‐\nuted under the terms of a permission notice identical to this one.\n\nPermission  is  granted  to copy and distribute translations of this manual page into another\nlanguage, under the above conditions for modified versions, except that this  permission  no‐\ntice may be stated in a translation approved by the Foundation.\n\nFree Software Foundation                     Feb 02 2018                                   FORK(3am)",
            "subsections": []
        }
    },
    "summary": "fork, wait, waitpid - basic process management",
    "flags": [],
    "examples": [
        "@load \"fork\"",
        "...",
        "if ((pid = fork()) == 0)",
        "print \"hello from the child\"",
        "else",
        "print \"hello from the parent\""
    ],
    "see_also": [
        {
            "name": "filefuncs",
            "section": "3am",
            "url": "https://www.chedong.com/phpMan.php/man/filefuncs/3am/json"
        },
        {
            "name": "fnmatch",
            "section": "3am",
            "url": "https://www.chedong.com/phpMan.php/man/fnmatch/3am/json"
        },
        {
            "name": "inplace",
            "section": "3am",
            "url": "https://www.chedong.com/phpMan.php/man/inplace/3am/json"
        },
        {
            "name": "ordchr",
            "section": "3am",
            "url": "https://www.chedong.com/phpMan.php/man/ordchr/3am/json"
        },
        {
            "name": "readdir",
            "section": "3am",
            "url": "https://www.chedong.com/phpMan.php/man/readdir/3am/json"
        },
        {
            "name": "readfile",
            "section": "3am",
            "url": "https://www.chedong.com/phpMan.php/man/readfile/3am/json"
        },
        {
            "name": "revoutput",
            "section": "3am",
            "url": "https://www.chedong.com/phpMan.php/man/revoutput/3am/json"
        },
        {
            "name": "rwarray",
            "section": "3am",
            "url": "https://www.chedong.com/phpMan.php/man/rwarray/3am/json"
        },
        {
            "name": "time",
            "section": "3am",
            "url": "https://www.chedong.com/phpMan.php/man/time/3am/json"
        },
        {
            "name": "wait",
            "section": "2",
            "url": "https://www.chedong.com/phpMan.php/man/wait/2/json"
        },
        {
            "name": "waitpid",
            "section": "2",
            "url": "https://www.chedong.com/phpMan.php/man/waitpid/2/json"
        }
    ]
}