Solved

Start a sleep process and kill it woulthout using any intermediate files

Posted on 2010-11-19
13
455 Views
Last Modified: 2012-08-13
Start a sleep process and kill it woulthout using any intermediate files
0
Comment
Question by:sobeservices2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
13 Comments
 
LVL 4

Expert Comment

by:trythisone
ID: 34175904
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
0
 
LVL 8

Accepted Solution

by:
LunarNRG earned 500 total points
ID: 34175915
Something like this perhaps? If not, please clarify your question.  

#!/bin/bash

sleep 300 &
sleep_pid=$!

# ... do something ...

kill -TERM $sleep_pid

Open in new window


Or maybe ...

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

Open in new window

0
 

Author Comment

by:sobeservices2
ID: 34175988
I meen something like

sleep 100
sleep 100
then kill it
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
LVL 8

Expert Comment

by:LunarNRG
ID: 34176229
"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.

0
 

Author Comment

by:sobeservices2
ID: 34184331
#!/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
0
 
LVL 8

Expert Comment

by:LunarNRG
ID: 34185055
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.
0
 

Author Comment

by:sobeservices2
ID: 34185070
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
0
 
LVL 8

Assisted Solution

by:LunarNRG
LunarNRG earned 500 total points
ID: 34185258
OK, got it.

The second example, was just that, an example -- and one possible (if not recommended or common) reason for wanting to manipulate a sleep process in a script. It assumes you will assign a value to the variable 'some_condition', based on the needs of your particular script. If the first example works for your purposes, it is safe to ignore the second.

However, if you want to play with the second example, give some_condition a value -- and add echo statements to expose the flow of the program. As in,

#!/bin/bash

sleep 300 &
sleep_pid=$!


some_condition=false
# uncomment the following to wait for the sleep process to end
#some_condition=true

if $some_condition; then
  echo "Waiting for sleep to end normally."
  until ! $(kill -0 $sleep_pid &> /dev/null); do
    sleep 1
  done
  # do_something
else
  echo "Terminating the sleep process."
  kill -TERM $sleep_pid
  # do_something_else
fi

Open in new window



HTH
0
 

Author Comment

by:sobeservices2
ID: 34185267
what do you mean by give some_condition a value?
0
 
LVL 8

Expert Comment

by:LunarNRG
ID: 34185276
As specified in the most recent example code ...

some_condition=false

Open in new window

0
 

Author Comment

by:sobeservices2
ID: 34188431
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?
0
 

Author Closing Comment

by:sobeservices2
ID: 34188452
Was good
0
 
LVL 8

Expert Comment

by:LunarNRG
ID: 34188570
$! 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
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question