Link to home
Start Free TrialLog in
Avatar of Member_2_4942450
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
Avatar of trythisone
trythisone
Flag of United States of America image

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
Avatar of LunarNRG
LunarNRG
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Member_2_4942450
Member_2_4942450

ASKER

I meen something like

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.

#!/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
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 ...

#!/bin/bash

sleep 300 &
sleep_pid=$!

# ... do something ...

kill -TERM $sleep_pid

Open in new window


... as it starts "a sleep process" and kills it without "using any intermediate files". If you disagree, please clarify your question.
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
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
what do you mean by give some_condition a value?
As specified in the most recent example code ...

some_condition=false

Open in new window

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?
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