LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-31-2006, 08:01 AM   #1
nutthick
Member
 
Registered: Jun 2004
Distribution: Slack
Posts: 214

Rep: Reputation: 30
Bash Sleep vs crontab and bash serial port


I've got a couple of questions that I need some advice on.

1. I need to have a piece of software running in the background as root, to make some system changes based on what it finds in a file. I was either going to run a script on startup and then sleep the script for a minute, or going to set the script to run from cron. Does anyone know of any performance issues to doing it either way?

2. I need to do some basic RS232 through the serial port. It will literally be one byte out and then reading a reply of one byte in. Can bash do serial comms, if so does anyone have some source code or a website with details?

I'm trying to stay away from doing some C, but if I have no choice then... I'd really like to do it in bash.

Any advice?

Thanks
 
Old 05-31-2006, 09:38 AM   #2
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
I am using both. For processes which I like to run at intervals of 2 minutes or larger I use cron.

For shorter intervals (I have some scripts running at 20 seconds intervals) I use sleep.

I have never checked it, but I don't expect a performance penalty for one or the other. When a process is put to sleep, well... it sleeps and doesn't use any resources.

Cron is being run once every interval anyway, whether or not you program is called so I don't see any performance issues either.

Sleep in your own program offers finer granularity than cron so it is a logical choice for shorter intervals.

jlinkels
 
Old 05-31-2006, 06:45 PM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,356

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Actually, there is an extra overhead via cron because it has to create a process + env before it can execute it. From a user's pt of view it may not be obvious timing-wise, but it's definitely there.
I agree that for restart intervals of less than say 5 mins, running your own daemon is (prob) better; longer than that and I'd use use cron.
There's no hard + fast rule though ...
 
Old 06-01-2006, 01:04 AM   #4
nutthick
Member
 
Registered: Jun 2004
Distribution: Slack
Posts: 214

Original Poster
Rep: Reputation: 30
I thought it was going to be the other way round. As if you have several processes sleeping then you have several processes monitoring for wakeup, whereas cron would be just one process sleeping waiting to fire off the others.

Still I completed the job with sleep and the performance seems OK.

Thanks
 
Old 06-01-2006, 02:42 AM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,356

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
That's because a daemon is sleeping, then doing something (internally).
cron is a sleeping (not much) daemon that then creates an external standalone process+env for each entry at each time requested.
In kernel terms, process creation is much more expensive than 'activating' an already extant process.
The more jobs cron has to do and more often, the more 'creations' take place.
As I said:
From a user's pt of view it may not be obvious timing-wise, but it's definitely there.
For any one job/program, the diff is usually un-noticeable, but but the cumulative load will show (eg top) if there are a lot of jobs.
 
  


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
Reading crontab into bash array nutthick Programming 2 05-22-2006 12:44 PM
BASH :Reading the crontab, and editing it semaja2 Programming 4 02-05-2006 06:43 AM
Using crontab in a bash script nro Linux - Newbie 3 08-26-2005 08:04 PM
Why can't I read in data from the serial port using a bash script? tjt Linux - Newbie 1 06-17-2004 12:21 AM
bash script for database searching using crontab saurya_s Linux - Software 5 01-22-2004 08:53 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:40 AM.

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