Thursday, September 16, 2004

Background processes in Perl

Problem: i don't know how to set a task as a background process. My code's running on GNU/Linux, btw. I've tried adding an & before the last backticks, but it still waits for the process to end.
What it does is run the external program, so that it's output goes to a file. And i want it to run in the background.
I've tried this:
`$exe_file > $tmp_file &`;

BTW, my program is run by the user in a web browser.
I could see the perl script running by running "ps"
And i know my code works, because simple operations gives the right output.

What i plan to do is to run that binary file as an executable, and make my script check if there's already a file outputed by that binary - by refreshing the page every 5 seconds, using a meta tag (html) - and if there already is a file, it'll read the file and print it to the page.
I checked the documentation (perldoc perlfunc), but found that only "fork" is related to backgrounding - i "grepped" the documentation for "background" and only the fork part has that word.

Any help would be appreciated.

Sunday, September 12, 2004

Input configuration files for EMANS

At first, the configuration files, specifically, lp_in.conf looked like this:

# shows how the input will be asked
defaults=m:2,n:2
Title=t:title
no of variables=s:n
no of constraints=s:m
Objective Function=(f:c,"x")[n]
Constraints={(f:a,"x")[n],"GLE",f:b}[m]
lower-bound=(f:lval,"x"," ")[n]
upper-bound=(f:uval,"x"," ")[n]
Cords, Fritz, Lindsay, and Adrian, however, suggested another way to write it. That is, to make it more "expandable." The above configuration just works with up to two-dimensions. This is quite ideal, since the part i'm working on is the web interface, which would only have virtually up to two-dimensional input. However, one could devise a way to allow users to input data in n-dimensions, like having them input in multiple pages, or in multiple color schemes, etc...
Now, it looks like this:
# shows how the input will be asked
defaults=m:2,n:2
Title=t:title
no of variables=s:n
no of constraints=s:m
Objective Function=(f:c,"x",$n)[n:'ADD']
Constraints=((f:a,"x",$n)[n:'ADD'],"GLE",f:b)[m]
lower-bound=(f:lval,"x",$n," ")[n]
upper-bound=(f:uval,"x",$n," ")[n]
Notice that the braces "{}" are replaced by parenthesis "()" and at the part where you'd indicate the number of elements are in an array (the one enclosed by brackets "[]"), the "joining action" done to each element in that array. For this, each element - as indicated by 'ADD' - is added to each other.