Home > database >  How do i make my C program run in the background on windows?
How do i make my C program run in the background on windows?

Time:12-03

I need my C program to run in the background, so without any open window or without blocking the terminal if run from there.

I can't find much info on how to do it online.

CodePudding user response:

To make a C program run in the background on Windows, you can use the start command in the command prompt. This will start the program in a separate window and allow you to continue using the command prompt while the program is running.

Here is an example of how to use the start command to run a C program in the background:

Open the command prompt by pressing the Windows key R on your keyboard, typing "cmd" into the run dialog, and pressing Enter.

Navigate to the directory that contains the C program you want to run. For example, if the program is in the "C:\Programs" folder, you would type cd C:\Programs and press Enter.

Run the start command followed by the name of the C program. For example, if the program is named "myprogram.exe", you would type start myprogram.exe and press Enter. This will start the program in a separate window and return you to the command prompt.

To check that the program is running, you can use the tasklist command. This will show you a list of all the programs currently running on your system, including the C program you just started.

Note that this method will not actually make the C program run as a true background process. The program will still have its own window and be visible in the taskbar, and it will continue to run even if you close the command prompt. However, it will allow you to continue using the command prompt while the program is running, which can be useful in certain situations.

CodePudding user response:

Windows supports two program types; GUI and console.

Console applications automatically get a console window if the parent process does not already have one.

GUI applications do not get a console and they can have 0, 1 or multiple windows. If you don't create a window your application is basically only visible in Task manager. GUI applications typically use WinMain as the startup function instead of main. Notepad.exe is a GUI application that creates a window.

You need to tell the compiler/linker that you are creating a GUI program. If you are using Visual Studio, it probably has a project template you can use.

  • Related