process

Q&A's, tips, howto's
Locked
newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

process

Post by 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.

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

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
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

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.

newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

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.

pjot
Posts: 733
Joined: Thu Feb 26, 2004 10:19 pm
Location: The Hague, The Netherlands
Contact:

Post by pjot »

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
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

thanks, that will work

Lutz

ps: status* should be set to NULL

pjot
Posts: 733
Joined: Thu Feb 26, 2004 10:19 pm
Location: The Hague, The Netherlands
Contact:

Post by pjot »

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
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

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
Posts: 733
Joined: Thu Feb 26, 2004 10:19 pm
Location: The Hague, The Netherlands
Contact:

Post by pjot »

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

Locked