GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 28-Aug-2004, 17:09
dabigmooish's Avatar
dabigmooish dabigmooish is offline
Member
 
Join Date: May 2004
Location: Baltimore (middle of Canton)
Posts: 165
dabigmooish will become famous soon enough

Checking system date/time


Hey everyone I was just wondering how you could set a program to run in the backaround and at every set time to run a particular program. I kinda know running the program you could use a system out command, but how can you make a program that simply runs in the backaround? And how can you check the system time?
__________________
"To argue with a person who has renounced the use of reason is like administering medicine to the dead."
-Thomas Paine
www.sullivan-county.com/deism.htm
  #2  
Old 30-Aug-2004, 07:17
dsmith's Avatar
dsmith dsmith is offline
Senior Member
 
Join Date: Jan 2004
Location: Utah, USA
Posts: 1,351
dsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of light
Quote:
Originally Posted by dabigmooish
Hey everyone I was just wondering how you could set a program to run in the backaround and at every set time to run a particular program. I kinda know running the program you could use a system out command, but how can you make a program that simply runs in the backaround? And how can you check the system time?

For the first part of the problem, I would use a fork. I have written a small tutorial on it. It is written towards linux, but I am sure that Windows has a counterpart, if not the exact same call.

As for the system time & date, I would use the time call. Also, I would make sure that if you are going to loop, that you use some type of sleep function.

Here is a small sample that you may have to modify a bit to get working in windows:
CPP / C++ / C Code:
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <time.h>

int main(){

  pid_t 	pid;
  int		i;
  time_t	timer;


  /* Attempt to fork and check for errors */
  if( (pid=fork()) == -1){
    fprintf(stderr,"Fork error. Exiting.\n");  /* something went wrong */
    exit(1);
  }

  if(pid){
    /* A positive (non-negative) PID indicates the parent process */
	fprintf(stderr,"Parent exiting\n");
	exit(0);
  }
  else{
    /* A zero PID indicates that this is the child process */
	for(i=0;i<10;i++){
		//CHECK FOR POSSIBLE EXECUTION HERE
		timer = time(&timer);
		fprintf(stderr,"Checking at %s\n",ctime(&timer));
		sleep(1);
	}
	fprintf(stderr,"Child exiting\n");
	exit(0);
  }
  return 0;
}

This will print 10 times to the console, but you will still be able to process commands in the console, etc.

HTH
  #3  
Old 30-Aug-2004, 13:36
dabigmooish's Avatar
dabigmooish dabigmooish is offline
Member
 
Join Date: May 2004
Location: Baltimore (middle of Canton)
Posts: 165
dabigmooish will become famous soon enough
I like that ideal Dsmith and I will look into it some but what I ment by running in the backaround was to have like a system tray icon, i.e. no actual open programm window.
__________________
"To argue with a person who has renounced the use of reason is like administering medicine to the dead."
-Thomas Paine
www.sullivan-county.com/deism.htm
 
 

Recent GIDBlogHalfway done! by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need suggestions on a template system Div MySQL / PHP Forum 1 15-Jul-2004 09:26
linux system calls emmie Computer Software Forum - Linux 4 23-May-2004 14:41
Athlon system locking up on start up. Is it MoBo, Processor, PSU or what? ebolaosu Computer Hardware Forum 8 26-Feb-2004 11:19
it worth checking this dima Free Web Hosting 1 23-Sep-2003 04:06
i = system ("cd c:\text"); :( kyle C Programming Language 1 25-Aug-2003 11:43

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 20:22.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.