Process spawns additional newLisps

Started by pjot, November 02, 2004, 01:24:44 PM

Previous topic - Next topic

pjot

Hi everybody,



I want to clone the complete current running newLisp program to a new instance. I use this trick:

(process (append (first (main-args)) " " (last (main-args))))

But for some reason I see additional newLisp processes running the program now. To simplify my question, the following procedure:

peter@Starcrater:~$ newlisp
newLISP v.8.2.5 Copyright (c) 2004 Lutz Mueller. All rights reserved.

> (process "newlisp")
1365
> newLISP v.8.2.5 Copyright (c) 2004 Lutz Mueller. All rights reserved.

>

...works, I receive a new newLisp prompt. However, if I look at my processlist, I see this:

peter     1364  1138  0 23:09 pts/1    00:00:00 newlisp
peter     1365  1364  0 23:09 pts/1    00:00:00 newlisp
peter     1366  1365  0 23:09 pts/1    00:00:00 newlisp

So actually, I see 3 newLisp processes, but I'ld expect only 2. How is this possible? I tried the same thing in Windows, but there only 2 processes are visible.



When I exit the spawned newLisp, I arrive at the Unix prompt immediately, with 2 remaining newLisp processes in memory, which must be killed manually.



Peter

gregben

#1
Not that it helps, but I tried (process "newlisp") under Solaris 8 and got

three processes too.

Lutz

#2
On Linux/UNIX newLISP forks a thread which launches the child process and then waits for the child process to complete. When the child process has completed the extra thread also exits. The extra 'newlisp' entry you see in the 'ps' table is that thread created (1365 in your example).



Normally you would the newlisp process launched having execute some program. In your interactive test, both newISP seem to compete for std I/O and you don;t really know which process you are exiting (I suspect the first one).



Lutz

pjot

#3
Indeed the first one is exited. I guess there is no other way of cloning the current running newLisp program completely? A FORK seems only to fork a function or a part of a program. (Thanks also GregBen for the Solaris test.)

Lutz

#4
A fork in newLISP clones everything not only the function you called in the fork, which is just the entry point and when that function exists your thread exists too. So it just depends on what the function is you are calling in the fork, but all the other functions defined and variables set are also cloned into the fork.



Lutz