
fashimpaur
User
/ Moderator
Sep 5, 2002, 6:07 AM
Post #6 of 6
(953 views)
|
|
Re: [fashimpaur] Spawning Child Process in Multiple Environments
[In reply to]
|
Can't Post
|
|
Hey all, For the sake of documenting solutions, I wanted to let you know how to do this process. Please read my previous post for more information about what is being done here and how I am getting the results from the forked process. Here was my solution: # main thread would execute # Following is some pseudo code ... if (search is not in progress){ get search criteria; print 'waiting' html with flag set to indicate search has started startSearch(); # once this runs, new thread is spawned and this one exits 12 lines down } else { if (process output does not exist){ redisplay some waiting html to user that auto submits form again to check after 6 second wait } else { process search results based on process output } } exit; sub startSearch { local $SIG{CHLD} = 'IGNORE'; open( STDIN, "</dev/null"); open( STDOUT, ">>/dev/null"); open( STDERR, ">>../logs/daemon_logfile"); fork and exit; # main thread stops here and new thread resumes from this point my @args = ("perl", "expSearch.pl"); exec @args or print STDERR "[ ".localtime()." ] PID: $$ Can't perform search. Error: $!\n"; }
Note that there is a lot of missing code to explain all the logic conditions handled and what to do if the application is running the search too long ( a timeout built in). But, this is for the general informational use of anyone trying to fork that process. I did not think fork worked on Windows platform, but found that it is somewhat functional in the newer releases. This worked with no problems for me to develop the application but since the final platform would be a UNIX box, I knew that it should work there completely as expected. If anyone is trying to do something like this and they have problems doing it, I would be glad to assist you. This is the second most unusual thing I have ever done with perl. The first was to parse x509 digital certificates. Which, if you have the desire to discuss those, I can also help there too. Thanks to all who helped, Dennis $a="c323745335d3221214b364d545". "a362532582521254c3640504c3729". "2f493759214b3635554c3040606a0", print unpack"u*",pack "h*",$a,"\n\n";
|