process and sleep function error on a self-calling script

Started by winger, October 14, 2013, 09:14:43 PM

Previous topic - Next topic

winger


;#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
Quote load
function?
Quotesilent
 function no effect.
Welcome to a newlisper home:)

http://www.cngrayhat.org\">//http://www.cngrayhat.org

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

I THINK This's a bug ?!



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


#ps.lsp
(println "Current PIS is "  (sys-info 7) " ---> " (last $main-args))
(exit)


Quote$ 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\">//http://www.cngrayhat.org

Lutz

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

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.


(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


(define (p1)
    (dotimes (n 2) (process (string "/usr/bin/newlisp " " p2.lsp " n))
    (timer 'p1 5))
 (p1)
Welcome to a newlisper home:)

http://www.cngrayhat.org\">//http://www.cngrayhat.org

Lutz

good solutions!