[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
fork(3am) confusion
From: |
b3ak3r |
Subject: |
fork(3am) confusion |
Date: |
Tue, 23 Jul 2024 10:22:39 -0600 |
User-agent: |
Mozilla Thunderbird |
Hello,
I recently stumbled upon the Gawk fork(3am) extension and have been
trying to use it in a loop without much success.
# --
@load "fork"
function Child(N) {
printf Fmt, "Child", N, PROCINFO["pid"], PROCINFO["ppid"]
wait()
}
BEGIN {
Fmt = "%8s #%d: PID=%8d PPID=%8d\n"
# forks prior fork(s)..
for (i=1; i<=4; i++) {
fork(Child(i))
}
}
# --
Per the comment in the BEGIN section, this code appears to fork prior
forks, and not all output gets displayed: piping the output to sort(1)
shows 64 lines of output though only 15 lines are displayed otherwise.
I'd like for the code to *not* do that and produce a single line out
output per child, 4 lines total in this case.
Probably I'm miss-understanding how fork(3am) is intended to be used.
Also doing "fork(Child(i))" is likely wrong; the manpage does not
indicate that fork() can take an argument though it appears to.
My end goal in all this is to couple fork() with Gawk's Internet socket
capability to create multi-threading in a simple network service. Is
that a possibility with fork(3am) ? Also can someone point me towards
examples of working gawk code utilizing fork(3am)?
Regards,
-B
- fork(3am) confusion,
b3ak3r <=