LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-16-2009, 01:34 PM   #1
btncix
Member
 
Registered: Aug 2009
Location: USA
Posts: 141

Rep: Reputation: 26
what is the difference between at and sleep


I saw this come up in
this thread, but I thought I should start a separate thread for this question. Please let me know if I should have kept this in the original thread.

I was wondering what the difference is in using at or sleep. The case I'm thinking of comes from the thread linked above:

case 1:
somewhere in /etc/rc.d/rc.local
at -f /path/to/script now + 5 min

case 2:
somewhere in /etc/rc.d/rc.local
/path/to/your/script &
at the top of /path/to/your/script
sleep 300


Specifically, I was wondering in terms of process context switch - which I know little about. I assume there is an efficient context switch in case 1 such that /path/to/script won't be eating up cpu cycles the first 5 mintues of its calling. Is the behavior the same for case 2? I assume the sleep command does not eat up cpu cycles according to this thread, but I wasn't sure.

I would also appreciate any other difference that you see between the two cases. Thanks.
 
Old 09-16-2009, 01:41 PM   #2
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
Quote:
sleep 300
will wait 300 sec before it executes, rc.local script will also wait for 300 sec, untill the script is executed; before it can continue

Quote:
at -f /path/to/script now + 5 min
The script will be executed in 5 minutes, rc.local will continue to execute

Last edited by repo; 09-16-2009 at 02:06 PM.
 
Old 09-16-2009, 02:05 PM   #3
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
Note also that at will run in a separate thread (from the script), and it will have its own environment. See the at(1) manpages for more info.
 
Old 09-16-2009, 05:35 PM   #4
kapilbajpai88
Member
 
Registered: Jul 2008
Location: Bangalore, India
Distribution: RHEL
Posts: 235

Rep: Reputation: 41
Question

Hi All,

Sorry to interrupt in between, but what would be the better idea of scheduling a job...'at' or 'sleep' , especially when the cpu resources are the major concern for the execution of the job?

Regards,
Kapil
 
Old 09-16-2009, 05:39 PM   #5
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
Quote:
Originally Posted by kapilbajpai88 View Post
Sorry to interrupt in between, but what would be the better idea of scheduling a job...'at' or 'sleep' , especially when the cpu resources are the major concern for the execution of the job?
Depends what you want to do
How about cron ?
 
Old 09-16-2009, 05:44 PM   #6
kapilbajpai88
Member
 
Registered: Jul 2008
Location: Bangalore, India
Distribution: RHEL
Posts: 235

Rep: Reputation: 41
Question

Hi Repo,

Thank you for the reply....
I have a script that needs to be run in 1 hr of interval for three times in the night time. Script adds 100 records to Oracle table after every 1 hr. I was thinking to set 'at' like that it executes after every 1 hr on its own, but I lost it to stop and it keeps on executing after every 1 hr throughout the night untill unless we manually stops that.

can 'wait' solve out problem ??

Cheers,
Kapil.
 
Old 09-16-2009, 05:48 PM   #7
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
You can setup a cronjob for this
Take a look at
http://unixgeeks.org/security/newbie/unix/cron-1.html
 
Old 09-16-2009, 05:50 PM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,363

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Use cron for that: http://www.adminschoice.com/docs/cro...Crontab%20file
 
Old 09-16-2009, 06:01 PM   #9
kapilbajpai88
Member
 
Registered: Jul 2008
Location: Bangalore, India
Distribution: RHEL
Posts: 235

Rep: Reputation: 41
Thumbs up

Hi All,

I think CRON will be a better idea for my work...I will go through the links again in detail and will edit the script accordingly.

Thank You All,
Kapil.
 
Old 09-16-2009, 08:36 PM   #10
btncix
Member
 
Registered: Aug 2009
Location: USA
Posts: 141

Original Poster
Rep: Reputation: 26
I'm not clear on what repo posted:

Wouldn't the & allow the rest of rc.local to get executed without waiting for /path/to/your/script to finish executing?

Also, how does the sleep command work exactly. This thread seems to explain that the sleep command doesn't eat up cpu cycles, but that a context switch occurs with the process, and the operating system will awaken the process after 300 seconds. So during the 300 seconds, no cpu cycle is used for /path/to/your/script. Is my understanding of this correct?


case 2: note: you have TWO files here

somewhere in /etc/rc.d/rc.local
/path/to/your/script &

at the top of /path/to/your/script
sleep 300
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script to find the difference betwwn two file and place the difference to other kittunot4u Linux - General 3 07-19-2010 04:26 AM
use of sleep AdmiralFreezbee Linux - Software 7 12-09-2005 02:32 AM
Searching for Server (BOOTP/DHCP) <sleep> <sleep> .. .. Eileen Linux - Networking 12 10-21-2005 01:14 AM
Sleep Samoth Linux - General 1 05-01-2005 06:20 PM
sleep TroelsSmit Linux - Newbie 10 05-22-2004 01:17 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration