April 30th, 2008, 07:10 AM
How to make programs run in the background??
How do u make a program(which i wrote in C) run in the background.I use windows vista home premium.
April 30th, 2008, 08:10 AM
You're probably referring to a service, though it isn't necessarily so.
The concept of "background" is essentially a human concept and, indeed, the definition of "background" flip-flopped when computer use moved from local humans as attendants to local humans as users.
Originally the person working at the keyboard was considered a background process; now they're considered the foreground process.
April 30th, 2008, 09:44 AM
Oh darn! You gave your OS. I was hoping to tell you to put an & after the command when you invoke it, but that's UNIX.
In Windows, it's trivial. Run the program, then start up another program. The program that has the focus will be the "foreground" process, while the program that doesn't will be "running in the background".
If that's not what you mean, then please explain. Despite our reputation, we don't read minds.
April 30th, 2008, 11:51 AM
If you launch it from the cmd window (ie. not double-clicking on a fancy icon) you can try to call:
C:\whatever > start my_prog -my_option
This way your command shell won't wait for the program to terminate.
C:\whatever > my_prog -my_option
If you mean 'run it without anything appearing on screen, not even a console window' ,the answer is 'I don't know'. I've tried to do it myself, no luck. Unless the program is declared as a service, of course.
etienne:~ > %blow
fg: %blow: no such job
There are 10 kind of people:
- those who know binary
- those who don't.
April 30th, 2008, 01:17 PM
That's really simple. You build the code as a GUI application, (this supresses the console Window), and treat WinMain() as if it were a traditional main() (except it does not have the same argc, argv parameters).
Originally Posted by etienne141
If you are using MinGW or Cygwin you can suppress the console through the -mwindows option. You can then use either main() or WinMain() as the entry point.
If you use Dev-C++ there is an option to not create a console window (which sets the -mwindows option). This is set when you select a GUI build, but is available in console mode also. If you remove -mwindows from a GUI app, you get both your apps window (if you create one), and a console window - useful for 'printf' debugging of GUI apps or a command line interface to a graphical tool.
Comments on this post
"running in background" doesn't not exist in Win32 (preemptive multithreaded OS)
Comments on this post
While I think I see why you say that, Lucas, I'm pretty sure you're confusing the idea of a process 'moved to the background' (as in the older versions of MacOS, where a program would get suspended while another is running) and 'running in background' (which just means that it is not running interactively). A background process in Windows or Unix continues running; you just don't necessarily see the output of it actions.
Mind you, the classical idea of a background process in Unix slightly different, being tied to the shell: it was a process which was run from a shell command with an ampersand ('&') following the command string, which told the shell to launch the operation but then return to the prompt while the program continued running. It was primarily a way of starting a long operation while allowing you to continue working. While this is less critical in a GUI, where you can have several programs on the screen running independently and even several xterms at once, but it still is important in a lot of shell operations.
To be honest, the term 'background process' is a somewhat slippery one, as it can depend on the sort of system you are talking about and the context in which you are speaking of it. In the batch processing days, a background process wasn't running by definition; it was one which was waiting for a CPU slice, what today is usually referred to as a 'suspended' process. This use is rare today, and can be confusing if you read some of the older literature. In Windows, a background process is one where which runs without a window or taskbar item, and the term is sometimes used this way in Linux as well (though not often as it can be confused with the other use I mentioned above).