1Fsdb::Support::Freds(3)User Contributed Perl DocumentatioFnsdb::Support::Freds(3)
2
3
4
6 Fsdb::Support::Freds - an abstraction over fork and/or ithreads
7
9 use Fsdb::Support::Freds;
10 my $fred = new Fsdb::Support::Freds('new thread to do foo');
11 # or
12 my $fred = new Fsdb::Support::Freds('demo_fred',
13 sub { child_stuff(); exit 0; },
14 sub { say "child is done\n"; } );
15 $fred->join();
16 # or
17 $fred->detach();
18
19 This package provides an abstraction over fork that is something like
20 Perl's ithreads. Our goal is to abstract process creation and
21 collection, but none of the shared data like ithreads.
22
23 (Why "Freds"? Because it's fork-based thread-like things, and "Tasks"
24 seems too generic.)
25
26 new
27 $fsdb = new Fsdb::Support::Freds($description, $child_sub, $ending_sub);
28
29 For a process, labeling it with optional $DESCRIPTION then running
30 optional $CHILD_SUB in the subprocess, then running optional
31 $ENDING_SUB in the parent process when it exits.
32
33 $ENDING_SUB is passed three arguments, the fred, the shell exit code
34 (typically 0 for success or non-zero for failure), and the wait return
35 code (the shell exit code shifted, plus signal number).
36
37 It is the job of the $CHILD_SUB to exit if it wants. Otherwise this
38 function returns to the caller.
39
40 is_child
41 $fred->is_child();
42
43 Are we the child? Returns undef if parent.
44
45 info
46 $info = $fred->info();
47
48 Return a string description of the Fred.
49
50 error
51 $fred->error();
52
53 Non-zero if in error state.
54
55 exit_code
56 $fred->exit_code($full);
57
58 Exit code of a termintated fred. With $FULL, turn the full version
59 (including errors). Typically "0" means success.
60
61 _post_join
62 $fred->_post_join();
63
64 Internal cleanup after $FRED is terminated.
65
66 join
67 $fred->join();
68
69 Join a fred (wait for the process to finish). Returns -1 on error
70 (Including if not in the parent.)
71
72 join_any
73 my $fred = Fsdb::Support::Freds::join_any($BLOCK);
74
75 Join on some pending fred, without blocking (default) or blocking (if
76 $BLOCK) is set. Returns -1 on error. Returns 0 if something is
77 running but not finished.
78
79 Returns the $FRED that ends.
80
81 join_all
82 my $fred = Fsdb::Support::Freds::join_all();
83
84 Reap all pending threads.
85
86 END
87 Detect any non-repeaed processes.
88
89
90
91perl v5.36.0 2023-01-20 Fsdb::Support::Freds(3)