CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Execute a sub in the background

 



egzoti4en
New User

Feb 1, 2012, 5:00 AM

Post #1 of 3 (1422 views)
Execute a sub in the background Can't Post

Hello guys,

I really really need your help fast.

I'm doing a project and I have no idea how to do something.

Here is the deal.

I have a while cycle where i read every key pressed. When i press 'Enter' i want to execute a sub which has a while cycle in it but also there is a sleep in it.

Here is some example code :

do
{
if($key eq "\n")
#execute sub_example()
if($key eq "261)
#do something else
while ((key = getch()) ne ERR)

sub_example
{
do
{#.......
sleep 5# i really need to sleep it here
#....
while(...}
}

So my issue is that when i execute sub_example the program freezes and waits for the cycle in the sub to finish. I want it to run in the background and still have the possibility to read from the keyboard and do stuff.

Thank you very much for your help i really needed.


(This post was edited by egzoti4en on Feb 1, 2012, 5:11 AM)


FishMonger
Veteran / Moderator

Feb 1, 2012, 6:33 AM

Post #2 of 3 (1403 views)
Re: [egzoti4en] Execute a sub in the background [In reply to] Can't Post

See: perldoc -f fork
http://perldoc.perl.org/functions/fork.html


(This post was edited by FishMonger on Feb 1, 2012, 6:33 AM)


egzoti4en
New User

Feb 1, 2012, 7:46 AM

Post #3 of 3 (1396 views)
Re: [FishMonger] Execute a sub in the background [In reply to] Can't Post

Well i made it with threads and using detach, but now my issue is that i cannot stop it after i have detached the thread. Is there a way to kill a thread after detaching it

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives