GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
child-list.h
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 1993-2025 The Octave Project Developers
4//
5// See the file COPYRIGHT.md in the top-level directory of this
6// distribution or <https://octave.org/copyright/>.
7//
8// This file is part of Octave.
9//
10// Octave is free software: you can redistribute it and/or modify it
11// under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// Octave is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with Octave; see the file COPYING. If not, see
22// <https://www.gnu.org/licenses/>.
23//
24////////////////////////////////////////////////////////////////////////
25
26#if ! defined (octave_child_list_h)
27#define octave_child_list_h 1
28
29#include "octave-config.h"
30
31#include <csignal>
32
33#include <list>
34
35#include <sys/types.h>
36
38
40{
41public:
42
43 // Do whatever to handle event for child with PID (might not
44 // actually be dead, could just be stopped). Return true if
45 // the list element corresponding to PID should be removed from
46 // list. This function should not call any functions that modify
47 // the child_list.
48
49 typedef bool (*child_event_handler) (pid_t, int);
50
51 child (pid_t pid = -1, child_event_handler f = nullptr)
52 : m_pid (pid), m_handler (f), m_have_status (0), m_status (0)
53 { }
54
55 child (const child&) = default;
56
57 child& operator = (const child&) = default;
58
59 ~child () = default;
60
61 // The process ID of this child.
62 pid_t m_pid;
63
64 // The function we call if an event happens for this child.
65 child_event_handler m_handler;
66
67 // Nonzero if this child has stopped or terminated.
68 sig_atomic_t m_have_status;
69
70 // The m_status of this child; 0 if running, otherwise a m_status value
71 // from waitpid.
73};
74
76{
77public:
78
79 OCTAVE_DEFAULT_CONSTRUCT_COPY_MOVE_DELETE (child_list)
80
81 void insert (pid_t pid, child::child_event_handler f);
82
83 void remove (pid_t pid);
84
85 void reap ();
86
87 bool wait ();
88
89private:
90
91 std::list<child> m_list;
92};
93
94OCTAVE_END_NAMESPACE(octave)
95
96#endif
child(const child &)=default
pid_t m_pid
Definition child-list.h:62
child_event_handler m_handler
Definition child-list.h:65
~child()=default
child(pid_t pid=-1, child_event_handler f=nullptr)
Definition child-list.h:51
int m_status
Definition child-list.h:72
sig_atomic_t m_have_status
Definition child-list.h:68
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
F77_RET_T const F77_DBLE const F77_DBLE * f
#define OCTAVE_API
Definition main.in.cc:55