perl question using system() and sleep() problem

A place for discussion of topics that are not specific to ZoneMinder. This could include Linux, Video4Linux, CCTV cameras or any other topic.
Post Reply
ynn
Posts: 152
Joined: Fri Mar 17, 2006 2:30 am

perl question using system() and sleep() problem

Post by ynn »

Hi,

I want to ask you guys, how to run my_program.pl without interupting or
stoping the sleep() below, because what happened was the sleep stops
doing its job waiting for the system("my_program.pl") to be completed.
i tried using exec but exec stop the sleep right away.

Thanks for any help.

while(1) {
system ( "my_program.pl" );
sleep 60;
}
User avatar
zoneminder
Site Admin
Posts: 5215
Joined: Wed Jul 09, 2003 2:07 pm
Location: Bristol, UK
Contact:

Post by zoneminder »

What are you trying to get you program to do?

There are 3 ways I do process spawning stuff (1) Use system, I hardly ever use this (2) use `<command>` or qx, I use this for most things or (3) if you want to do something else while the command is being run or to limit a wait, use fork and exec. Without knowing what you want it to do I can't recommend which to use.

You could also use perlthreads if you are feeling brave :shock:
Phil
ynn
Posts: 152
Joined: Fri Mar 17, 2006 2:30 am

Post by ynn »

Thanks for the reply, I am trying to start another daemon program if the time meets. this is cronlike program, so for example, if the time is equal to midnight, my daemon script would be run. so right now i am using system(), but the bad thing about system() is that it will wait until the child process is finish, so my parent daemon process stucks there not doing anything while the time hits midnight. :)

which one do you recommend me to use in this case phil?

thanks alot.
User avatar
zoneminder
Site Admin
Posts: 5215
Joined: Wed Jul 09, 2003 2:07 pm
Location: Bristol, UK
Contact:

Post by zoneminder »

I would suggest perhaps something using fork and exec. You can have a look at zmdc.pl for examples of how to use them, though your script won't need to be so complicated. There are plenty of other simpler examples on the web and in 'perldoc perltut' I think.
Phil
ynn
Posts: 152
Joined: Fri Mar 17, 2006 2:30 am

Post by ynn »

thank you phil
Post Reply