process

Started by newdep, March 04, 2004, 12:30:06 PM

Previous topic - Next topic

newdep

Hello Lutz,



The function 'process backgrounds a process, which under unix/linux can

cause <defuncs> (not so bad as long as newlisp tracks the child ).

These <defuncs> are caused by IO under unix/linux, but...



To be able to controll this 'process launched by newlisp it would be very handy

to have a PID returned. This way under newlisp the child can still be killed

from within newlisp, rather beining on itself and kills when newlisp is closed.



example:

> ( process "lisple" )

12302



>(define (killpid pid) (import "/lib/libc.so.6" "kill") (kill pid 9))

0





Norman.
-- (define? (Cornflakes))

Lutz

#1
this is what I can do in 7.5.8 (you can do it now to try out):



in nl-filesys.c in the function p_process() (there are two versions for Win32 and UNIX):



change the last line:



old: return(true);



new: return(stuffInteger(forkResult));



This will give you the pid of the newLISP child process, that pid+1 is the pid of the process launched by the child process.



i.e:



(process "kedit") => 2412



2412 => newLISP childprocess

2413 => kedit pid



Lutz

newdep

#2
Hello Lutz,



Yes the implant works, but its impossible to kill his PID afterwards, thats due to the fact that the process belongs to newlisp. If newlisp would stop

and the child will stay there as defunc then still you cant kill the child,

so actualy the process PID return is of no use :-) I thought it would, but

its useless..  :-)



Norman.
-- (define? (Cornflakes))

newdep

#3
Hello Lutz,



Haha..i was already building my way into translating process or ! output towards the input of newlisp ;-) But what did i just see ;-) Yes a well implmented 'exec that moves the output into lists..Ha great..Thankx



Norman.
-- (define? (Cornflakes))

pjot

#4
If this issue is about reaping DEFUNCT child processes, I had the same problem with my GTK-server. This sample C code can be used to solve it. It will callback a C function which cleans up the defuncts, so you do not have to exit newLISP. Maybe you can test it yourself, newdep... :-)





-------------------------



/* Declare struct */

struct sigaction sa;



/* Register zombie process reaper with callback function */

sa.sa_handler = sig_handler;



/* Do not block other signals */

sigemptyset(&sa.sa_mask);

sa.sa_flags = SA_RESTART;



if (sigaction(SIGCHLD, &sa, NULL) < 0) {

   printf("Could not set signal handler!n");

   perror("sigaction");

   exit(-1);

}



-------------



/* Callback for reaping defuncts */



void sig_handler(int signal)

{

int status;

/* Reap child without blocking */

if (waitpid(-1, &status, WNOHANG) < 0) return;

}

Lutz

#5
thanks, that will work



Lutz



ps: status* should be set to NULL

pjot

#6
Yep, you're right there. I am not sure if it works on all UNICES however. But it will work on Linux > 2.2 with signal.h.

Lutz

#7
I think the zombie process problem is only on Linux, if it doesn't work on BSD, I probably don't need it



Lutz

pjot

#8
Defuncts also appear on Solaris and Tru64Unix. Even today I had trouble fixing defuncts on Solaris.