Page 1 of 1

Process spawns additional newLisps

Posted: Tue Nov 02, 2004 9:24 pm
by pjot
Hi everybody,

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

Code: Select all

(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:

Code: Select all

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:

Code: Select all

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

Posted: Tue Nov 02, 2004 9:41 pm
by gregben
Not that it helps, but I tried (process "newlisp") under Solaris 8 and got
three processes too.

Posted: Tue Nov 02, 2004 9:49 pm
by Lutz
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

Posted: Tue Nov 02, 2004 9:54 pm
by pjot
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.)

Posted: Thu Nov 04, 2004 12:50 pm
by Lutz
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