tags:

views:

95

answers:

3

May you convert this tiny code to Bash code :

user/bin/perl sleep(300); system("killall -9 perl &"); sleep(5)

Thanks in Advance .

+2  A: 
sleep 300
killall -9 perl &
sleep 5
Matthew Flaschen
+6  A: 
#!/bin/bash
sleep 300
killall -9 perl &
sleep 5
rarbox
+1  A: 

The perl program will kill not only all other perl processes, but also itself, so the functional equivalent translation would be something like

#!/bin/bash
sleep 300
killall -9 perl &
kill -9 $$ &
sleep 5

The final sleep 5 is probably never executed in the original script or in this one, although it is possible that the sleep command at least starts to execute.

If the reason behind translating into bash is exactly that, i.e. the program is supposed not to commit suicide, the other answers are better.

As Dennis Williamson said, in either case, your script should probably not use kill -9 and generally not globally kill, but it depends on your environment if it may have bad side effects.

Moritz Both