# Ubuntu server; running non blocking commands



## cassamine (Nov 22, 2002)

Hey all,

I'm running an ubuntu-server with webmin but no GUI. Yaay!

well in CLI mode I knew just how to run 1 command at a time.
so to run two command. i.e. command1 and command2
i would create a bash script like so

```
[SIZE="3"]command1
command2[/SIZE]
```
the problem is if _command1_ never terminates, _command2_ is never executed.

after some googling I found out how to run two commands together asynchronously.

It's simple really, for others looking how:
command1 & command2
the ampersand in between makes both/multiple commands execute simultaneously without waiting for first/previous command to finish.

Now the issue is when I run this script, i can't do other day-to-day tasks as CLI is waiting for this scritp to finish, which it never will as command1 and command2 are both never ending commands. they are basically constantly doing something to the system.

bottomline: I have managed to run both commands together but now I can't do anything in CLI as its waiting for my bash script to end.

isn't there a way i can make an application or bash script run in non-blocking mode? to have my CLI free for other things?

a cheat could be to use webmin for executing such scripts but I think ubuntu-server must have a better solution to start never-ending applications, like servers, in the background.

also I would like to autostart this script in non-blocking mode so i don't have to do this everytime, but that's relatively simpler I guess.

any ideas will be greatly appreciated.

Cheers!
Johl


----------



## lotuseclat79 (Sep 12, 2003)

Hi Johl,

Typically, from a command line, to be able to have control from a Terminal window when executing a single command, I have always used the ampersand (&) at the end in order to shove the command process into the backrgound (as opposed to the foreground where you must wait for termination of the command in order to proceed).

Example:
$ command &

You might experiment with what you have already done, i.e. try:
$ command1 & command2 &

I think that this will execute both of your commands individually in the background, one after the other in order.

I am not sure your explanation above in your message is accurate, i.e. I think that command1 was initially executed in the background, and command2 was executed in the foreground because you terminated the command line with <Enter>.

When things go awry and a Terminal window hangs or appears to, in order to get control back, there are several alternatives. For instance, you can instantiate another Terminal window, or if you think the Terminal window is stuck by some system problem, you can try Force Quit - right-click and Add it's icon to the main panel in order to use it, then left-click on the Force Quit icon, and then left-click inside the Terminal window which should terminate the Terminal window.

-- Tom


----------



## cassamine (Nov 22, 2002)

Forgot to reply sooner..

That worked  yaay

Thanks mates


----------



## tomdkat (May 6, 2006)

lotuseclat79 said:


> When things go awry and a Terminal window hangs or appears to, in order to get control back, there are several alternatives. For instance, you can instantiate another Terminal window, or if you think the Terminal window is stuck by some system problem, you can try Force Quit - right-click and Add it's icon to the main panel in order to use it, then left-click on the Force Quit icon, and then left-click inside the Terminal window which should terminate the Terminal window.


Um, he's not running in GUI mode so there are no icons and no "force quit". 

In this case, he'll need to open a new login session, login, and start kill processes OR he can possibly issue a Control-Z to suspend the foreground process(es) and then he can kill them or resume them, as appropriate.

Johl, in Unix land, the "CLI" is called the "shell". The Unix shell has a LOT of capability for running processes in the background as well as doing neat things with scripting. The more you learn about using the Unix shell, the stronger the Force will be with you. 

On Ubuntu, bash is the shell you're using so you might want to read up on the bash shell to learn its features, functions, and capabilities.

Enjoy!

Peace...


----------

