Bash: run an executable file in background
Any executable in linux can be run in the background as follows:
$ ./yourExecutable.exe&
Add the &
character at end. (Assuming yourExecutable.exe
is in the current working directory)
How to kill it later on?
$ ps -ax | grep yourExecutable.exe
You will get an output like:
9384 pts/7 S+ 0:00 grep yourExecutable.exe
25082 pts/7 T 0:00 yourExecutable.exe&
Kill the second process using SIGKILL
. That is the one you executed in the background.
$ kill -9 25082
Bash script to run linux executables in background
The man page for disown
says you can use nohup
for the same purpose.
I would recommend that because it is more specific about which command is affected. You can make a cd
command affect only some commands by grouping them under a "subshell". Putting all of that together yields:
#!/bin/bash
echo "Starting ServiceA. Currect dir is : $PWD"
(cd AppAFolder && chmod +x App-A && nohup ./App-A &>/dev/null &)
echo "Starting ServiceB. Currect dir is : $PWD"
(cd AppBFolder && chmod +x App-B && nohup ./App-B &>/dev/null &)
run an executable file in the background and prevent it from opening windows using python
Python can't prevent a child process from opening windows. That also means it can't turn something with a UI into a daemon / background process.
You will have to look into the documentation of the application mousecounter
to see whether it supports command line options to hide / disable the window.
Running exe file in background in windows 10
You can make easily a service out of it using the Non-Sucking Service Manager
It can be used as commonad-line tool and it has a graphical user interface.
In the System services you can start/stop the service and make it run mode Automatic
How to loop run an executable multiple time without waiting for it to finish
Bash executes foreground processes in a synchronous way. To do it as you want, you have to launch the process in the background using &
, as pointed out in the comments. You can make a function that implements the desired behavior for a file and then call it inside the loop.
The only problem with a separate asynchronous function, is that the counter
variable will not necessarily match your actual numbered filenames, so if you want them to keep the original number, you must extract it explicitly from the original name, or use an explicit variable. I will use the second approach in the following snippet:
#!/bin/bash
# Function to encapsulate your processing
# First arg: input file
# Second arg: counter
process_file(){
cd /some/dir/for/out/files/outputs/
mkdir file$2
cd file$2
/dir/where/executable/located/./run $1
}
for i in {0..65..1} # Iterate through the numbers, not the files, so we can use $i as a counter
do
input_file=/directory/where/input/files/are/file$i.txt
process_file $input_file $i & # Ampersand to launch in the background
done
Edit:
This is actually overkill for this case, as I'm pretty sure having you very same script, but with &
appended to your run
command, would do it. However, this approach is scalable in case you want to add more sequential processing for each single file and still have it in parallel for all files.
Run exe in background
Your syntax for Start-Process is wrong, you don't need to reference powershell, just launch your program with the WindowStyle
param set
Start-Process "C:\Program Files\Prometheus.io\prometheus.exe" -WindowStyle Hidden
The WorkingDirectory
param can also be used to start the program in a specific directory
Start-Process "C:\Program Files\Prometheus.io\prometheus.exe" -WorkingDirectory "C:\Program Files\Prometheus.io" -WindowStyle Hidden
Related Topics
Mysqld Service Stops Once a Day on Ec2 Server
How to Read Websocket Response in Linux Shell
Bluez: Advertise Service/Gatt Server Example
Ld_Library_Path Doesn't Seem to Work
How to Realize a Diff Function
Hiding Github Token in .Gitconfig
Minimizing Copies When Writing Large Data to a Socket
Understanding Tcpdump Filter & Bit-Masking
What Is The Significance of This_Module in Linux Kernel Module Drivers
Manage Source Under Git and Svn Simultanously - Does It Make Sense
Difference Between Tcp_Max_Syn_Backlog and Somaxconn
Cross Compiling for Mips Router from X86
Does Kernel's Panic() Function Completely Freezes Every Other Process