00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "awk.h"
00027
00028
00029
00030 static NODE *
00031 do_fork(tree)
00032 NODE *tree;
00033 {
00034 int ret = -1;
00035 NODE **aptr;
00036
00037 if (do_lint && tree->param_cnt > 0)
00038 lintwarn("fork: called with too many arguments");
00039
00040 ret = fork();
00041
00042 if (ret < 0)
00043 update_ERRNO();
00044 else if (ret == 0) {
00045
00046
00047 aptr = assoc_lookup(PROCINFO_node, tmp_string("pid", 3), FALSE);
00048 (*aptr)->numbr = (AWKNUM) getpid();
00049
00050 aptr = assoc_lookup(PROCINFO_node, tmp_string("ppid", 4), FALSE);
00051 (*aptr)->numbr = (AWKNUM) getppid();
00052 }
00053
00054
00055 set_value(tmp_number((AWKNUM) ret));
00056
00057
00058 return tmp_number((AWKNUM) 0);
00059 }
00060
00061
00062
00063
00064 static NODE *
00065 do_waitpid(tree)
00066 NODE *tree;
00067 {
00068 NODE *pidnode;
00069 int ret = -1;
00070 double pidval;
00071 pid_t pid;
00072 int options = 0;
00073
00074 if (do_lint && tree->param_cnt > 1)
00075 lintwarn("waitpid: called with too many arguments");
00076
00077 pidnode = get_argument(tree, 0);
00078 if (pidnode != NULL) {
00079 pidval = force_number(pidnode);
00080 pid = (int) pidval;
00081 options = WNOHANG|WUNTRACED;
00082 ret = waitpid(pid, NULL, options);
00083 if (ret < 0)
00084 update_ERRNO();
00085 } else if (do_lint)
00086 lintwarn("wait: called with no arguments");
00087
00088
00089 set_value(tmp_number((AWKNUM) ret));
00090
00091
00092 return tmp_number((AWKNUM) 0);
00093 }
00094
00095
00096
00097 NODE *
00098 dlload(tree, dl)
00099 NODE *tree;
00100 void *dl;
00101 {
00102 make_builtin("fork", do_fork, 0);
00103 make_builtin("waitpid", do_waitpid, 1);
00104 return tmp_number((AWKNUM) 0);
00105 }