1Mojo::IOLoop::ReadWriteUPsreorceCsosn:t:rSiebsustieModonj(Po3e:)r:lIODLoocoupm:e:nRteaatdiWorniteProcess::Session(3)
2
3
4
6 Mojo::IOLoop::ReadWriteProcess::Session - Session manager for handling
7 child processes.
8
10 use Mojo::IOLoop::ReadWriteProcess::Session;
11 use Mojo::IOLoop::ReadWriteProcess qw(process);
12
13 my $session = process()->session; # or Mojo::IOLoop::ReadWriteProcess::Session->singleton
14
15 $session->enable; # Modifies your SIG_CHLD
16
17 $session->on(collected => sub { warn "Process ".(shift->pid)." collected! "});
18 $session->on(collected_orphan => sub { warn "Orphan process collected! "});
19
20 $session->enable_subreaper(); # Mark the current process as subreaper
21 $session->disable_subreaper(); # Disable subreaper
22
23 $session->reset(); # Resets events and clear the process tables
24 $session->clean(); # Stop all processes that result as running and reset
25
27 Mojo::IOLoop::ReadWriteProcess::Session is a session manager for the
28 collected processes
29
31 Mojo::IOLoop::ReadWriteProcess::Session inherits all events from
32 Mojo::EventEmitter and can emit the following new ones.
33
34 SIG_CHLD
35 $session->on(SIG_CHLD => sub {
36 my ($self) = @_;
37 ...
38 });
39
40 Emitted when we receive SIG_CHLD.
41
42 collected
43 $session->on(collected => sub {
44 my ($self, $process) = @_;
45 ...
46 });
47
48 Emitted when child process is collected and it's return status is
49 available.
50
51 protect
52 $session->on(protect => sub {
53 my ($self, $detail) = @_;
54 my ($cb, $signal) = @$detail;
55 ...
56 });
57
58 Emitted when protected callbacks are fired.
59
60 collected_orphan
61 $session->on(collected_orphan => sub {
62 my ($self, $process) = @_;
63 $process->pid;
64 $process->exit_status;
65 ...
66 });
67
68 Emitted when child process is collected and it's exit status is
69 available. Note: here are collected processes that weren't created
70 with Mojo::IOLoop::ReadWriteProcess.
71
72 register
73 $session->on(register => sub {
74 my ($self, $process) = @_;
75 $process->pid;
76 $process->exit_status;
77 ...
78 });
79
80 Emitted when a process is registering to a session.
81
83 Mojo::IOLoop::ReadWriteProcess::Session inherits all attributes from
84 Mojo::EventEmitter and implements the following new ones.
85
86 subreaper
87 use Mojo::IOLoop::ReadWriteProcess::Session qw(session);
88 session->enable_subreaper;
89 my $process = Mojo::IOLoop::ReadWriteProcess->new(code => sub { print "Hello ".$_[1] }, args => "User" );
90 $process->start();
91 $process->on( stop => sub { shift()->disable_subreaper } );
92 $process->stop();
93
94 # The process will print "Hello User"
95
96 Mark the current process (not the child) as subreaper on start. It's
97 on invoker behalf to disable subreaper when process stops, as it marks
98 the current process and not the child.
99
100 collect_status
101 Defaults to 1, If enabled it will automatically collect the status of
102 the children process. Disable it in case you want to manage your
103 process child directly, and do not want to rely on automatic collect
104 status. If you won't overwrite your "SIGCHLD" handler, the "SIG_CHLD"
105 event will be still emitted.
106
107 handler()
108 use Mojo::IOLoop::ReadWriteProcess::Session qw(session);
109 session->handler(sub {});
110
111 Default handler for SIG_CHLD processing, used when "disable()" is
112 invoked.
113
115 Mojo::IOLoop::ReadWriteProcess::Session inherits all methods from
116 Mojo::EventEmitter and implements the following new ones.
117
118 enable()
119 use Mojo::IOLoop::ReadWriteProcess::Session qw(session);
120 session->enable();
121
122 Sets the SIG_CHLD handler.
123
124 disable()
125 use Mojo::IOLoop::ReadWriteProcess::Session qw(session);
126 session->disable();
127
128 Disables the SIG_CHLD handler and reset with the previous one.
129
130 enable_subreaper()
131 use Mojo::IOLoop::ReadWriteProcess qw(process);
132 my $p = process()->enable_subreaper;
133 # or
134 use Mojo::IOLoop::ReadWriteProcess::Session qw(session);
135 session->enable_subreaper;
136
137 Mark the current process (not the child) as subreaper. This is used
138 typically if you want to mark further childs as subreapers inside other
139 forks.
140
141 use Mojo::IOLoop::ReadWriteProcess::Session qw(session);
142
143 my $master_p = process(
144 sub {
145 my $p = shift;
146 $p->enable_subreaper;
147
148 process(sub { sleep 4; exit 1 })->start();
149 process(
150 sub {
151 sleep 4;
152 process(sub { sleep 1; })->start();
153 })->start();
154 process(sub { sleep 4; exit 0 })->start();
155 process(sub { sleep 4; die })->start();
156 my $manager
157 = process(sub { sleep 2 })->subreaper(1)->start();
158 sleep 1 for (0 .. 10);
159 $manager->stop;
160 return session->all->size;
161 });
162
163 $master_p->subreaper(1);
164 $master_p->on(collect_status => sub { $status++ });
165
166 $master_p->on(stop => sub { shift()->disable_subreaper });
167 $master_p->start();
168 session->all->size();
169 ....
170
171 disable_subreaper()
172 use Mojo::IOLoop::ReadWriteProcess qw(process);
173 my $p = process()->disable_subreaper;
174
175 Unset the current process as subreaper.
176
177 prctl()
178 use Mojo::IOLoop::ReadWriteProcess qw(process);
179 my $p = process();
180 $p->prctl($option, $arg2, $arg3, $arg4, $arg5);
181
182 Internal function to execute and wrap the prctl syscall, accepts the
183 same arguments as prctl.
184
185 reset()
186 use Mojo::IOLoop::ReadWriteProcess qw(session);
187 session->reset;
188
189 Wipe the process tables.
190
191 clean()
192 use Mojo::IOLoop::ReadWriteProcess qw(session);
193 session->clean;
194
195 Wipe the process tables, but before attempt to stop running procesess.
196
197 all()
198 use Mojo::IOLoop::ReadWriteProcess::Session qw(session);
199 my $collection = session->all;
200 $collection->size;
201
202 Returns a Mojo::Collection of Mojo::IOLoop::ReadWriteProcess that
203 belongs to a session.
204
205 all_orphans()
206 use Mojo::IOLoop::ReadWriteProcess::Session qw(session);
207 my $collection = session->all_orphans;
208 $collection->size;
209
210 Returns a Mojo::Collection of Mojo::IOLoop::ReadWriteProcess of
211 orphaned processes that belongs to a session. They are automatically
212 turned into a Mojo::IOLoop::ReadWriteProcess, also if processes were
213 created by "fork()".
214
215 all_processes()
216 use Mojo::IOLoop::ReadWriteProcess::Session qw(session);
217 my $collection = session->all_processes;
218 $collection->size;
219
220 Returns a Mojo::Collection of all Mojo::IOLoop::ReadWriteProcess known
221 processes that belongs to a session.
222
223 contains()
224 use Mojo::IOLoop::ReadWriteProcess::Session qw(session);
225 my $collection = session->contains(13443);
226 $collection->size;
227
228 Returns true if the pid is contained in any of the process tables.
229
230 resolve()
231 use Mojo::IOLoop::ReadWriteProcess::Session qw(session);
232 my $process = session->resolve(12233);
233
234 Returns the Mojo::IOLoop::ReadWriteProcess process identified by its
235 pid if belongs to the process table.
236
237 orphan()
238 use Mojo::IOLoop::ReadWriteProcess::Session qw(session);
239 my $process = session->orphan(12233);
240
241 Returns the Mojo::IOLoop::ReadWriteProcess process identified by its
242 pid if belongs to the process table of unknown processes.
243
244 register()
245 use Mojo::IOLoop::ReadWriteProcess::Session qw(session);
246 my $process = session->register('pid' => Mojo::IOLoop::ReadWriteProcess->new);
247
248 Register the Mojo::IOLoop::ReadWriteProcess process to the session.
249
250 unregister()
251 use Mojo::IOLoop::ReadWriteProcess::Session qw(session);
252 my $process = session->unregister(123342);
253
254 Unregister the corresponding Mojo::IOLoop::ReadWriteProcess with the
255 given pid.
256
257 collect()
258 use Mojo::IOLoop::ReadWriteProcess::Session qw(session);
259 my $process = session->collect(123342 => 0 => undef);
260
261 Collect the status for the given pid.
262
263 protect()
264 use Mojo::IOLoop::ReadWriteProcess::Session qw(session);
265 use POSIX;
266
267 my $return = session->protect(sub { print "Hello World\n" });
268
269 session->protect(sub { print "Hello World\n" } => SIGTERM);
270
271 Try to protect the execution of the callback from signal interrupts.
272
274 session()
275 use Mojo::IOLoop::ReadWriteProcess::Session qw(session);
276 session->enable_subreaper;
277
278 Returns the Mojo::IOLoop::ReadWriteProcess::Session singleton.
279
281 You can set the MOJO_EVENTEMITTER_DEBUG environment variable to get
282 some advanced diagnostics information printed to STDERR.
283
284 MOJO_EVENTEMITTER_DEBUG=1
285
286 Also, you can set MOJO_PROCESS_DEBUG environment variable to get
287 diagnostics about the process execution.
288
289 MOJO_PROCESS_DEBUG=1
290
292 Copyright (C) Ettore Di Giacinto.
293
294 This library is free software; you can redistribute it and/or modify it
295 under the same terms as Perl itself.
296
298 Ettore Di Giacinto <edigiacinto@suse.com>
299
300
301
302perl v5.32.1 202M1o-j0o1:-:2I7OLoop::ReadWriteProcess::Session(3)