- Subject: Annoying problem with subprocesses
- From: sdupont@xxxxxxx
- Date: Mon, 27 Jan 2003 15:07:49 +0000
Hi all,
I'm using JED (thanks to John and all who contributed)
for all my development work and particularly the subprocess-feature
of JED I'm using very often.
There I noticed the following annoying problem:
I'm using one special buffer (call it '*proc*') in which a
subprocess (program under development) gets started, killed
and started again (with the following slang function):
-*- mode: slang; -*-
variable pid = -1;
variable cmd = "proc";
variable buf = "*proc*";
define run_proc() {
if (bufferp(buf)) {
ERROR_BLOCK {
% clears kill_process() error if no proc is running
_clear_error();
}
kill_process(pid);
}
pop2buf(buf);
pid = open_process(getenv("SHELL"), "-c", cmd, 2);
set_process(pid, "output", "");
}
In most of the times "proc" is a "long running" GUI programm
(Yes, I can end the programm externally, but it is
much more convenient to end it with kill_process()).
After starting "proc" for the second time (after it's
predecessor was killed with kill_process()) the following
happens:
I get an error "process '0' does not exist." and JED enters
an infinite loop in which it tries to read input from process 0
(which does not exist any more) instead of reading from new)
process 1. This leaves the editor unusable.
I tried to track down the problem with the debugger but (as
often with race conditions) if JED runs under the debugger,
everything works as expected :(
Ok, using printf I found the following situation causes the problem:
1. the process (0) gets killed in jed_close_process(),
signal_handler will do cleanup (but not yet)
2. new process (1) is created with open_process(),
no cleanup done so far
3. sys_input_pending() is trying to read_process_input()
and than it happens "what never should happen":
Since cleanup wasn't done or wasn't ready, Num_Subprocesses
is 2 (0 and 1) though in fact there is only one (1).
I tried to fix this problem by forcing a call to get_process_status()
in jed_close_process() (which is there but commented out).
But this is not enough: since the process is still flagged "ALIVE"
get_process_status() returns immediately without doing the cleanup.
Flagging the process 'EXITED' before the call to get_process_status()
does the trick (jprocess.c):
int jed_close_process (int *fd) /*{{{*/
{
[...]
p->flags = PROCESS_EXITED;
get_process_status(p);
return 0;
} /*}}}*/
This solved the problem, but I'm not too happy with this solution
since I neither know if this change has any harmfull effects
which I haven't noticed so far, nor if it works on other OS (than
Linux).
Any ideas?
Greetings
Stefan
--------------------------
To unsubscribe send email to <jed-users-request@xxxxxxxxxxx> with
the word "unsubscribe" in the message body.
Need help? Email <jed-users-owner@xxxxxxxxxxx>.
[2003 date index]
[2003 thread index]
[Thread Prev] [Thread Next]
[Date Prev] [Date Next]