LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Wireless Networking (https://www.linuxquestions.org/questions/linux-wireless-networking-41/)
-   -   Writing a Shell Script with a Time Parameter (https://www.linuxquestions.org/questions/linux-wireless-networking-41/writing-a-shell-script-with-a-time-parameter-525705/)

Siva4Linux 02-05-2007 04:41 AM

Writing a Shell Script with a Time Parameter
 
Hello there,

I want to write a shell script (preferably a Bourne Shell script) that allows me to fork and run certain number of processes for a given period (t) of time. If you haven't got my point yet, let me explain it briefly. The purpose of my experiment is to compare the performance of two different routing protocols (one is mine and the other is somebody else's) in our wireless Linux-based testbed in terms of their power-efficincy. Hence, the idea is to test the performance with the same VoIP (gphone) application under each routing protocol for a given period of time, while keeping all the other environmental settings the same. I have written a special software that periodically monitors as to how many packets have been sent and received in the whole 6-node testbed and how much energy has been depleted. For this purpose, I need to run each routing protocol, gphone and other processes for "t" hours and then stop them. Can somebody please let me know how this can be performed using a script. I have come up with a follwing script:

pid1 = fork("~/gphone -c 192.168.20.3)
pid2 = fork("../../routing_protocol)
.................................................
pidn = fork("../../monitor_program)
sleep t*60*60*1000 && kill ${pid1} ${pid2} ${pidn}

Do you think that the above script would do the job ?

Thanks in advance for taking your invaluable time to answer my question.

Best Regards,

Siva

wjevans_7d1@yahoo.co 02-05-2007 06:29 AM

Two things to keep in mind:

1. Bash doesn't have a "fork" directive.
2. The sleep command in bash is in terms of seconds, not milliseconds. Sleep t*60*60*1000 will sleep 1000*t hours.

Try this:

Code:

~/gphone -c 192.168.20.3 &
../../routing_protocol &
../../monitor_program &
sleep t*60*60
jobs -p > temporary_file
kill $(cat temporary_file)

Hope this helps.

Siva4Linux 02-05-2007 06:56 AM

Thanks wjevans_7d1@yahoo.co


All times are GMT -5. The time now is 09:18 PM.