Linux Programming Question

txrandom

Diamond Member
Aug 15, 2004
3,773
0
71
I have the following script running:

#!/bin/sh
while [ 1 ]; do
php timer.php 1
sleep 1.5
done

Does "sleep 1.5" get called after "php timer.php 1" is finished or is each call fired instantly after the previous one?

I actually have two scripts like the ones above and may eventually have even more, so I'm figuring out what are the effects of combining them like so:

#!/bin/sh
while [ 1 ]; do
php timer.php 1
php timer.php 2
sleep 1.5
done

So does each call wait on the other one to finish? or do they fire off right after each other?
 

txrandom

Diamond Member
Aug 15, 2004
3,773
0
71
I just ended up testing it myself and found out it does wait for the previous script to complete.

What I want to do is run two php timer.php scripts concurrently, wait for them to complete, and then sleep 1.5 seconds. Would I do something like this?

#!/bin/sh
while [ 1 ]; do
php timer.php 1 &
php timer.php 2 &
wait
sleep 1.5
done


Nevermind, just tested and everything workings. I guess I shouldn't be too afraid of trying new things on Linux.
 

Crusty

Lifer
Sep 30, 2001
12,684
2
81
Originally posted by: txrandom
I just ended up testing it myself and found out it does wait for the previous script to complete.

What I want to do is run two php timer.php scripts concurrently, wait for them to complete, and then sleep 1.5 seconds. Would I do something like this?

#!/bin/sh
while [ 1 ]; do
php timer.php 1 &
php timer.php 2 &
wait
sleep 1.5
done


Nevermind, just tested and everything workings. I guess I shouldn't be too afraid of trying new things on Linux.

Never be afraid unless you're running as root(terrible idea) or possibly in a shared environment where if you hose the box others will lose work.
 

Ken g6

Programming Moderator, Elite Member
Moderator
Dec 11, 1999
16,515
4,370
75
Well, there are some malicious "joke" codes some people post on the Internet that you should avoid using. There's some things you can do with "rm" that you should avoid doing unless you have a backup of your entire home directory. Some people like posting some code that looks like a bunch of punctuation characters, which defines a function that runs recursively and overloads your system. I'm not posting them here so nobody does anything stupid with them.

If ever you're really afraid of trying something, load up a small Linux (like Puppy Linux) in a VirtualBox, and try it there; it should be impossible to hose the rest of your system from there.
 

Crusty

Lifer
Sep 30, 2001
12,684
2
81
I assumed that not running other people's code without understanding what it does would be common sense :p

Either way, your home directory should be backed up anyways. Also, aliasing rm to rm -i helps a lot too in the case that you do accidentally rm something you didn't want to.
 

Kirby

Lifer
Apr 10, 2006
12,028
2
0
Originally posted by: Ken g6
Some people like posting some code that looks like a bunch of punctuation characters, which defines a function that runs recursively and overloads your system. I'm not posting them here so nobody does anything stupid with them.

Fork bomb? :p
 

degibson

Golden Member
Mar 21, 2008
1,389
0
0
Originally posted by: nkgreen
Originally posted by: Ken g6
Some people like posting some code that looks like a bunch of punctuation characters, which defines a function that runs recursively and overloads your system. I'm not posting them here so nobody does anything stupid with them.

Fork bomb? :p

I, unlike Ken g6, have no fear of posting fork bombs.

echo "int main() { while(1) fork(); }" > fb.c && gcc fb.c && ./a.out
 

Crusty

Lifer
Sep 30, 2001
12,684
2
81
Originally posted by: degibson
Originally posted by: nkgreen
Originally posted by: Ken g6
Some people like posting some code that looks like a bunch of punctuation characters, which defines a function that runs recursively and overloads your system. I'm not posting them here so nobody does anything stupid with them.

Fork bomb? :p

I, unlike Ken g6, have no fear of posting fork bombs.

echo "int main() { while(1) fork(); }" > fb.c && gcc fb.c && ./a.out

That's not nearly obfuscated enough though!
 

degibson

Golden Member
Mar 21, 2008
1,389
0
0
Originally posted by: Crusty
Originally posted by: degibson
Originally posted by: nkgreen
Originally posted by: Ken g6
Some people like posting some code that looks like a bunch of punctuation characters, which defines a function that runs recursively and overloads your system. I'm not posting them here so nobody does anything stupid with them.

Fork bomb? :p

I, unlike Ken g6, have no fear of posting fork bombs.

echo "int main() { while(1) fork(); }" > fb.c && gcc fb.c && ./a.out

That's not nearly obfuscated enough though!

Posting something actually dangerous would surely violate the rules of the forum. Posting something amusing however does not. :)