emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Handling of asynchronously called process orphans


From: Ralf Angeli
Subject: Handling of asynchronously called process orphans
Date: Sat, 31 Dec 2005 18:25:07 +0100

On the AUCTeX list the question arose if it were possible to get
output from xdvi in a separate buffer.  For this to work without
blocking Emacs we'd need to call xdvi asynchronously via
`start-process'.  Now the problem is that xdvi forks and kills its
parent process.  And if xdvi was called from withing Emacs the child
process will be killed as well.  We are currently working around this
problem by using `call-process' with a value of 0 for the `buffer'
argument, but this does not allow for the output to be gathered.  An
option would be to call xdvi with the -nofork command line option but
I don't know yet if this option has been supported long enough and as
the string for calling xdvi is a user option this may lead to problems
if the user forgets to specify -nofork.  So I wonder if there is a way
of calling xdvi from within Emacs which prevents the child process
from being killed.

I hope you don't mind me asking this on emacs-devel rather than on
help-gnu-emacs, but I don't know if this is just stupidity on my side,
a bug, an inevitable deficiency, or something else.

In case you need an example to play with and don't want to mess with
xdvi (which will only fork in certain situations), here is a small C
program:

--8<---------------cut here---------------start------------->8---
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int
main()
{
  pid_t pid;
  int i;

  switch(pid=fork())
    {
    case -1:
      perror("fork");
      exit(1);

    case 0:
      for (i=0; i<5; i++)
        {
          sleep(1);
          printf("This is the child process.\n");
        }
      break;
      
    default:
      printf("This is the parent process.\n");
      exit(0);
    }

  return 0;
}
--8<---------------cut here---------------end--------------->8---

After compiling you can call it with something like
(start-process "my-process" "foo" "/path/to/program")
and compare the output in buffer `foo' to the one you get if the
program is called from a terminal.

-- 
Ralf





reply via email to

[Prev in Thread] Current Thread [Next in Thread]