4 Copyright (C) 1999-2000 Timo Sirainen
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 static unsigned int childcheck_tag;
30 static int signal_pidwait;
32 /* add a pid to wait list */
33 void pidwait_add(int pid)
35 pids = g_slist_append(pids, GINT_TO_POINTER(pid));
38 /* remove pid from wait list */
39 void pidwait_remove(int pid)
41 pids = g_slist_remove(pids, GINT_TO_POINTER(pid));
44 /* return list of pids that are being waited.
45 don't free the return value. */
46 GSList *pidwait_get_pids(void)
51 static int child_check(void)
56 /* wait for each pid.. */
57 for (tmp = pids; tmp != NULL; tmp = next) {
58 int pid = GPOINTER_TO_INT(tmp->data);
61 if (waitpid(pid, &status, WNOHANG) > 0) {
62 /* process terminated, remove from list */
63 signal_emit_id(signal_pidwait, 2, tmp->data,
64 GINT_TO_POINTER(status));
65 pids = g_slist_remove(pids, tmp->data);
71 void pidwait_init(void)
74 childcheck_tag = g_timeout_add(1000, (GSourceFunc) child_check, NULL);
76 signal_pidwait = signal_get_uniq_id("pidwait");
79 void pidwait_deinit(void)
83 g_source_remove(childcheck_tag);