-2

(Sorry,I do a little change in my answer)

I want to know can I write a program that runs at a specific time?Is there any way to run a program automatically? And another question:Can I write a program that runs whenever another program is executed?

Note that it does not matter what the OS is,and I want a way to be in program code,that is I write a line of code that do the operation,because I cannot prompt different users to change their OS options to do the operation.

Mohammad
  • 364
  • 1
  • 6
  • 17
  • What operating system, first of all. – druckermanly Jan 29 '15 at 07:45
  • @user2899162 it's tagged [c][windows]... – Theolodis Jan 29 '15 at 07:46
  • @user2899162:If it depends,Windows. – Mohammad Jan 29 '15 at 07:46
  • [Windows 7 - Schedule a task](http://windows.microsoft.com/en-au/windows/schedule-task#1TC=windows-7) – Henrik Jan 29 '15 at 07:49
  • possible duplicate of [Windows Scheduled Task and Console Application](http://stackoverflow.com/questions/14590313/windows-scheduled-task-and-console-application) – slugster Jan 29 '15 at 07:50
  • [Search of previous questions similar to this](http://stackoverflow.com/search?q=windows+schedule) – slugster Jan 29 '15 at 07:51
  • Well, it was appropriately tagged! My fault, I don't know how I missed that. You can use the task scheduler, a simple google search will provide a long list of examples. – druckermanly Jan 29 '15 at 07:53
  • "Can I write a program that runs whenever another program is executed?" It would be easier either 1) for the other program to launch it when it starts, or 2) for the firts program to start and sit in a loop checking periodically if the other has stared yet and then to begin its main fucntionality – Mawg says reinstate Monica Jan 29 '15 at 08:02
  • So you wan't a programm that decides by it self (no external tool) whilest it is not executing, when it hast to start its execution? – dhein Jan 29 '15 at 08:36

3 Answers3

2

On windows you have the task scheduler, which can execute a programm at a specific time, with a specific user etc.

On linux you got something similar. The cronjobs/crontabs. An introduction you can find here.

based on new question: What is the sense of this? You can't trigger your own program if it's not running. So basically your program must run in the background 24/7 and wait for events. Maybe you should take a look at this post.

Community
  • 1
  • 1
greenhoorn
  • 1,505
  • 2
  • 12
  • 34
1

In windows you are having the task scheduler and the AT command. You refer this link.

Community
  • 1
  • 1
Karthikeyan.R.S
  • 3,921
  • 1
  • 17
  • 31
0

you need to develop a Daemon/Service process whose job is only to execute your application at required intervals or at specific time.

GingerJack
  • 2,698
  • 1
  • 15
  • 17