process and sleep function error on a self-calling script

Q&A's, tips, howto's
Locked
winger
Posts: 46
Joined: Wed Mar 14, 2012 7:31 am

process and sleep function error on a self-calling script

Post by winger »

Code: Select all

;#t2.lsp
(set 'ARGS (main-args))
(define (get-arg argname  '_result)
    (let (ix (find argname ARGS))
        (and ix (pop ARGS ix))
        (if (catch (ARGS  ix) '_result) 
            (and (pop ARGS ix) _result)
            nil
        )
    )
)


(constant 'EXECUTE_PATH "/usr/bin/newlisp")

(constant 'ARG_SECOND "t2.lsp")

(constant 'TIME_CLOCK 4000)


(constant 'DEAD (get-arg "--dead"))

(when DEAD
    (write-file (string "t2_txt." (date-value)) (string (date-value)))
    (exit)
)

(while (not DEAD)
    (sleep 2000) ;; Two line code . actually only sleep 2 seconds !!!
    (sleep 2000) ;; Without this will generate an error !!!
    (println "Sleep... " TIME_CLOCK )
    (if CPID (destroy CPID))
    (set 'CPID (process  (join (map string (list EXECUTE_PATH  ARG_SECOND "--clock" TIME_CLOCK  "--dead 4free"  )) " ") ))
    (println "CPID :--> " CPID )
    (println (join (map string (list EXECUTE_PATH  ARG_SECOND "--clock" TIME_CLOCK  "--dead 4free"  )) " "))
    ;(sleep 2000)  ;;Here is also possible to insert the code. 
)
(exit)
t2.lsp is A self-calling script.
anyboday have idea?

And How to suppress output from return values from
load
function?
silent
function no effect.
Welcome to a newlisper home:)
http://www.cngrayhat.org

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

Re: process and sleep function error on a self-calling scrip

Post by Lutz »

Works well here on a Windows 7 system, with and without the second sleep at the beginning of the while loop and without error message.

The process function is non-blocking. When the child process has started the parent sits in one of the following sleep functions. When the child process finishes, it sends a signal to the parent where it interrupts the current sleep. This explanation is for UNIX like operating systems (seems not to be on Windows).

The silent function only suppresses the display of the return value in the console or terminal window, but it will not suppress the return value itself.

winger
Posts: 46
Joined: Wed Mar 14, 2012 7:31 am

Re: process and sleep function error on a self-calling scrip

Post by winger »

I THINK This's a bug ?!

Code: Select all

#p1.lsp
(while 1
    (sleep 5000)
    (dotimes (n 2)
        (process (string "/usr/bin/newlisp " " p2.lsp " n))
    )
)
(exit)

Code: Select all

#ps.lsp
(println "Current PIS is "  (sys-info 7) " ---> " (last $main-args))
(exit)
$ newlisp -v
newLISP v.10.5.4 32-bit on Linux IPv4/6 UTF-8 libffi.
$newlisp p1.lsp

p1 process --- 1 time
p1 process --- 2 time
Current PIS is 891 ---> 0
Current PIS is 892 ---> 1
p1 process --- 3 time
Current PIS is 894 ---> 0
....
oh.................. so rapid
Program did not sleep for 5 seconds, but has continued rapid execution.
sleep function does not execute.
Welcome to a newlisper home:)
http://www.cngrayhat.org

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

Re: process and sleep function error on a self-calling scrip

Post by Lutz »

The sleep in the parent process is interrupted when the child process returns. See my previous post.

winger
Posts: 46
Joined: Wed Mar 14, 2012 7:31 am

Re: process and sleep function error on a self-calling scrip

Post by winger »

VERY THX Lutz !
Everything there is reason.
My knowledge is so poor that it did not notice the problem is the signal.
Now I found two ways to avoid this problem.

Code: Select all

(signal 17 "ignore") ; The SIGCHLD signal is sent to the parent of a child process when it exits, is interrupted, or resumes after being interrupted. But can not guarantee that each signal is captured
Or use timer function

Code: Select all

(define (p1)
    (dotimes (n 2) (process (string "/usr/bin/newlisp " " p2.lsp " n)) 
    (timer 'p1 5))
 (p1)
Last edited by winger on Tue Oct 22, 2013 1:57 am, edited 1 time in total.
Welcome to a newlisper home:)
http://www.cngrayhat.org

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

Re: process and sleep function error on a self-calling scrip

Post by Lutz »

good solutions!

Locked