GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   Linux Gurus - Problem (https://gfy.com/showthread.php?t=349367)

Dusen 08-31-2004 07:40 AM

Linux Gurus - Problem
 
I'm exec()'ing a bourne shell program from PHP. For the moment, it is not possible to port this shell program to php. I also do not have access to the source.

The shell program is fed instructions from the php file which grabs them from a ascii file. The simplified php process is:

while not eof datafile
{
fgets(arg)
exec(program arg)
}

However, executing the program sometimes gets locked into loops where it will just sit there. I want to have some way to put a time limit.

Setting the script to call another php script (that only execs the program) with a maximum exec time will not work - max times are only while inside the php script.

And the bash ulimit can only control processor time used, not actually kill the program, correct?

Ideally I'd like do run something like:

exec (./timelimit5 program arg)

which would just kill the process if it exceeds 5 seconds.

But I'm lost. Any suggestions?

Benja 08-31-2004 07:53 AM

I'm not a Linux guru, but aren't shell programs unix commands in a plain file ? Shell programs are not compiled are they ? So you should have the source and be able to put a kind of timeout there no?

Well, just what I see from your post.

flexor 08-31-2004 08:44 AM

First of all, I would recomand rewriting it in Perl.

If you want to keep it in bash, try to use signals, something like this http://www.signaltonoise.net/library...ariables2.html

Or search Google for "bash timeout script"

[in a nutshell]

TimerOn()
{ ( o p e n accolade thingy here, obfuscate by GFY board code)
sleep $TIMELIMIT && kill -s 14 $$ &
# Waits XXX seconds, then sends sigalarm to script.
}

[...]
trap Int14Vector 14
#Int14Vector is a function called when sig 14 is traped by script


See sleep, kill and trap for details.



HIH

Dusen 08-31-2004 09:06 AM

I apologize - judging from the replies - I wasn't clear.

The program I am execing is a compiled C app under bash, it isn't a bash script. That is why I don't have the source. I can't rewrite it :(

flexor - thanks for the reply though, I will put that stuff into my "learning" notebook I keep for when I'm doing something in perl.

Babaganoosh 08-31-2004 09:08 AM

Check out "alarm" at http://void.lv/tools/

It should do what you need.

Dusen 08-31-2004 09:36 AM

Alarm did it. Many many many thanks.

:)


All times are GMT -7. The time now is 03:09 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123