{
    "mode": "info",
    "parameter": "wait",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/info/wait/json",
    "generated": "2026-08-04T14:18:48Z",
    "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\nzero in the child and the process-id number of the child in  the\nparent,  or  -1  upon error. In the latter case, ERRNO indicates\nthe problem.  In the child, PROCINFO[\"pid\"] and PROCINFO[\"ppid\"]\nare updated to reflect the correct values.\n\nwaitpid()\nThis  function takes a numeric argument, which is the process-id\nto wait for. The return value is that of the  waitpid(2)  system\ncall.\n\nwait() This  function  waits  for  the  first child to die.  The return\nvalue is that of the wait(2) system call.\n",
            "subsections": []
        },
        "BUGS": {
            "content": "There is no corresponding exec() function.\n\nThe interfaces could be enhanced to provide more facilities,  including\npulling out the various 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), in-\nplace(3am), ordchr(3am), readdir(3am),  readfile(3am),  revoutput(3am),\nrwarray(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 (C) 2012, 2013, 2018, Free Software Foundation, Inc.\n\nPermission  is  granted  to make and distribute verbatim copies of this\nmanual page provided the copyright notice and  this  permission  notice\nare preserved on all copies.\n\nPermission  is granted to copy and distribute modified versions of this\nmanual page under the conditions for verbatim  copying,  provided  that\nthe  entire  resulting derived work is distributed under the terms of a\npermission notice identical to this one.\n\nPermission is granted to copy and distribute translations of this  man-\nual page into another language, under the above conditions for modified\nversions, except that this permission notice may be stated in a  trans-\nlation 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": "place",
            "section": "3am",
            "url": "https://www.chedong.com/phpMan.php/man/place/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": "fork",
            "section": "2",
            "url": "https://www.chedong.com/phpMan.php/man/fork/2/json"
        },
        {
            "name": "waitpid",
            "section": "2",
            "url": "https://www.chedong.com/phpMan.php/man/waitpid/2/json"
        }
    ]
}