-
Notifications
You must be signed in to change notification settings - Fork 3
/
faked
executable file
·48 lines (41 loc) · 945 Bytes
/
faked
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
#!/usr/bin/ruby
require 'optparse'
OptionParser.new do |opts|
opts.banner = "Usage: faked [options]"
opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
options[:verbose] = v
end
end.parse!
Signal.trap("USR1") do
puts "faked terminating because of SIGUSR1..."
exit(1)
end
Signal.trap("TERM") do
puts "faked terminating..."
exit(0)
end
# fake startup: sleep for 0.5s between each message
puts "faked starting... phase 0"
sleep 0.5
puts "faked starting... phase 1"
sleep 0.5
puts "faked starting... phase 2"
sleep 0.5
puts "faked started!"
# main loop
# - create one child per second
# - each child sleeps for 10s before terminating
(1..86400).each do |i|
pid = fork do
# avoid being killed by CTRL+C
Process.setsid
Signal.trap("INT") {}
puts "faked[#{i}] child created"
sleep 10
puts "faked[#{i}] child stopping"
end
Process.detach(pid)
sleep 1
end
# sleep forever after one day
sleep