Member_2_4942450
asked on
Start a sleep process and kill it woulthout using any intermediate files
Start a sleep process and kill it woulthout using any intermediate files
Not exactly sure what you are asking, but you can use a ping command to act as a sleep command by just pinging your localhost
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I meen something like
sleep 100
sleep 100
then kill it
sleep 100
sleep 100
then kill it
"then kill it"
What do you mean by "it", exactly? The first sleep process, the second, the enclosing script?
You might want to give us more to work with, perhaps explain what problem you're attempting to solve, and what you've already tried.
What do you mean by "it", exactly? The first sleep process, the second, the enclosing script?
You might want to give us more to work with, perhaps explain what problem you're attempting to solve, and what you've already tried.
ASKER
#!/bin/bash
sleep 300 &
sleep_pid=$!
if $some_condition; then
# wait for sleep to end
until ! $(kill -0 $sleep_pid &> /dev/null); do
sleep 1
done
# do_something
else
# terminate sleep process
kill -TERM $sleep_pid
# do_something_else
fi
Did not work
sleep 300 &
sleep_pid=$!
if $some_condition; then
# wait for sleep to end
until ! $(kill -0 $sleep_pid &> /dev/null); do
sleep 1
done
# do_something
else
# terminate sleep process
kill -TERM $sleep_pid
# do_something_else
fi
Did not work
Going to need more to go on than "Did not work", unfortunately. What did not work? Did you receive an error message?
IMHO, the following answers your original question ...
... as it starts "a sleep process" and kills it without "using any intermediate files". If you disagree, please clarify your question.
IMHO, the following answers your original question ...
#!/bin/bash
sleep 300 &
sleep_pid=$!
# ... do something ...
kill -TERM $sleep_pid
... as it starts "a sleep process" and kills it without "using any intermediate files". If you disagree, please clarify your question.
ASKER
Ok what I did was cut an past your code into a blank script
so you code was the only thing in there
save it as test1
then I ran it and got this nothing
even chmod +x test1
I had to do a control break
to stop it
no error message was given
so you code was the only thing in there
save it as test1
then I ran it and got this nothing
even chmod +x test1
I had to do a control break
to stop it
no error message was given
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
what do you mean by give some_condition a value?
As specified in the most recent example code ...
some_condition=false
ASKER
Ok I did you're first one and that worked for me.
Plane and simple
The other just got a little to harry and but I tried.
Better just keep it simple for now
sleep 300 &
sleep_pid=$!
thanks
Oh what's the $! mean?
Plane and simple
The other just got a little to harry and but I tried.
Better just keep it simple for now
sleep 300 &
sleep_pid=$!
thanks
Oh what's the $! mean?
ASKER
Was good
$! is the built-in bash variable representing the pid of the last process run in the background.
You'll find more information on this topic here:
http://tldp.org/LDP/abs/html/internalvariables.html
The intro tutorial is also very good:
http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html
You'll find more information on this topic here:
http://tldp.org/LDP/abs/html/internalvariables.html
The intro tutorial is also very good:
http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html