Process spawns additional newLisps

Q&A's, tips, howto's
Locked
pjot
Posts: 733
Joined: Thu Feb 26, 2004 10:19 pm
Location: The Hague, The Netherlands
Contact:

Process spawns additional newLisps

Post 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

gregben
Posts: 20
Joined: Wed Mar 10, 2004 5:00 pm
Location: San Diego, California, USA

Post by gregben »

Not that it helps, but I tried (process "newlisp") under Solaris 8 and got
three processes too.

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

Post 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

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

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

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

Post 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

Locked