1
1
// ------------------------------------------------------------------------
2
2
// audioio-forked-streams.cpp: Helper class providing routines for
3
3
// forking for piped input/output.
4
// Copyright (C) 2000-2004 Kai Vehmanen
4
// Copyright (C) 2000-2004,2006 Kai Vehmanen
7
7
// eca-style-version: 3
319
320
* function must be called from the same thread as
320
321
* fork_child_for_read/write() was called.
322
void AUDIO_IO_FORKED_STREAM::clean_child(void)
323
void AUDIO_IO_FORKED_STREAM::clean_child(bool force)
324
if (fd_rep > 0) ::close(fd_rep);
326
/* close the pipe between this process and the forked child
327
* process, should terminate the forked application -> see
326
333
if (pid_of_child_rep > 0) {
336
/* Linux-specific flag to waitpid() for to wait for
337
* childs created by other threads */
340
/* wait until child process has exited */
342
int res = waitpid(pid_of_child_rep, &status, flags);
343
if (res == pid_of_child_rep && WIFEXITED(status)) {
344
ECA_LOG_MSG(ECA_LOGGER::system_objects, "Child process exit ok");
345
pid_of_child_rep = 0;
353
/* if 'killing you softly' didn't work, next try with SIGTERM */
354
if (force == true && pid_of_child_rep > 0) {
355
ECA_LOG_MSG(ECA_LOGGER::system_objects, "sending SIGTERM to child process");
356
/* close did not trigger exit, send SIGTERM */
327
357
kill(pid_of_child_rep, SIGTERM);
328
if (::getpid() == pid_of_parent_rep) {
329
waitpid(pid_of_child_rep, 0, 0);
330
pid_of_child_rep = 0;
333
ECA_LOG_MSG(ECA_LOGGER::system_objects, "WARNING: Parent-pid changed!");
358
pid_of_child_rep = 0;
336
361
if (tmp_file_created_rep == true) {
337
362
::remove(tmpfile_repp.c_str());
363
tmp_file_created_rep = false;