Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New Application Process from Bash Shell

I'm relearning UNIX commands to use git on windows using MINGW32.

When I launch a program, for example "$ notepad hello.txt" I can't use the shell again until I close the notepad file or CTRL-C in the shell.

How do I essentially fork a new process so I can use both programs?

like image 914
Tom Avatar asked Mar 12 '10 00:03

Tom


People also ask

How do I start a new process in shell?

A new process can be created by the fork() system call. The new process consists of a copy of the address space of the original process. fork() creates new process from existing process. Existing process is called the parent process and the process is created newly is called child process.

How do you call a program in bash?

In order to run a Bash script on your system, you have to use the “bash” command and specify the script name that you want to execute, with optional arguments. Alternatively, you can use “sh” if your distribution has the sh utility installed.


3 Answers

Add a & to the end of the command:

notepad hello.txt &
like image 93
Ignacio Vazquez-Abrams Avatar answered Oct 21 '22 07:10

Ignacio Vazquez-Abrams


Put an ampersand (&) at the end of the command line. That tells the shell to run the program in the background.

In UNIX, you can hit CTRL-z to suspend the currently running program (Instead of CTRL-c to kill it). Once it's suspended, you can use the 'bg' command to put it in the background. I don't think that will work on Windows, but you can try.

like image 16
JayM Avatar answered Oct 21 '22 09:10

JayM


You can also create an alias in your .rc file so you don't have to add the ampersands each time.

I had some trouble doing this in bash on Cygwin though.

I ended up having to create a separate script file and add an alias to point to it.

Script file contents (filename is "dtextpad"):

#!/bin/bash.exe

C:/Program\ Files/TextPad\ 5/TextPad.exe $@ &

Alias in my .bashrc:

alias tp='~/include/bin/dtextpad'

Now if I want to open a file in textpad, I can type tp filename

like image 2
Daniel Haley Avatar answered Oct 21 '22 08:10

Daniel Haley