-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmpmt1.awk
53 lines (47 loc) · 1.18 KB
/
mpmt1.awk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env awk
#
# mpmt1.awk: GNU AWK version of mpmt1.py
#
# License:
# Apache License, Version 2.0
# History:
# * 2023/12/03 v0.1 Initial version
# Author:
# Masanori Itoh <masanori.itoh@gmail.com>
# TODO:
# * Use getopt.
# * Study if thread model is possible.
# * Study if high precision timer is available.
#
@load "fork"
BEGIN {
num_context = 3
duration = 5
if (ARGC > 1)
num_context = ARGV[1]
if (ARGC > 2)
duration = ARGV[2]
printf("num_context: %d duration: %d\n", num_context, duration)
for (i = 0; i < num_context; i++) {
if ((pid = fork()) == 0) {
# child
#printf("hello from child %d\n", i)
ts_start = systime()
while (1) {
ts_now = systime()
if ((ts_now - ts_start) >= duration) {
printf("Expired...\n")
exit
}
}
} else {
# parent
#printf( "hello from parent: %s %d\n", pid, i)
pids[i] = pid
}
}
for (i = 0; i < num_context; i++) {
p = wait() #pid(pids[i])
printf("pid %d exit...\n", p)
}
}