#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2008
    Location
    Chennai
    Posts
    29
    Rep Power
    0

    How to make programs run in the background??


    Hi
    How do u make a program(which i wrote in C) run in the background.I use windows vista home premium.
  2. #2
  3. Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Jun 2005
    Posts
    5,964
    Rep Power
    4852
    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.
    Write no code whose complexity leaves you wondering what the hell you did.
    Politically Incorrect DaWei on Pointers Grumpy on Exceptions
  4. #3
  5. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,145
    Rep Power
    2222
    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.
  6. #4
  7. Paris est magique!
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2004
    Location
    France!
    Posts
    370
    Rep Power
    96
    If you launch it from the cmd window (ie. not double-clicking on a fancy icon) you can try to call:

    Code:
    C:\whatever > start my_prog -my_option
    instead of:

    Code:
    C:\whatever > my_prog -my_option
    This way your command shell won't wait for the program to terminate.

    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.
  8. #5
  9. Contributing User

    Join Date
    Aug 2003
    Location
    UK
    Posts
    5,109
    Rep Power
    1802
    Originally Posted by etienne141
    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.
    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).

    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.

    Clifford

    Comments on this post

    • sizablegrin agrees
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2008
    Posts
    25
    Rep Power
    0
    "running in background" doesn't not exist in Win32 (preemptive multithreaded OS)

    Comments on this post

    • sizablegrin disagrees : That's your personal definition. Not many would agree.
    • codergeek42 disagrees : In fact, having a pre-emptive multi-tasking OS by its very *definition* means that you can run backgrounded tasks/processes.
  12. #7
  13. Commie Mutant Traitor
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jun 2004
    Location
    Alpharetta, GA
    Posts
    1,806
    Rep Power
    1570
    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).
    Rev First Speaker Schol-R-LEA;2 JAM LCF ELF KoR KCO BiWM TGIF
    #define KINSEY (rand() % 7) λ Scheme is the Red Pill
    Scheme in Short Understanding the C/C++ Preprocessor
    Taming Python A Highly Opinionated Review of Programming Languages for the Novice, v1.1

    FOR SALE: One ShapeSystem 2300 CMD, extensively modified for human use. Includes s/w for anthro, transgender, sex-appeal enhance, & Gillian Anderson and Jason D. Poit clone forms. Some wear. $4500 obo. tverres@et.ins.gov

IMN logo majestic logo threadwatch logo seochat tools logo