Live Chat & Podcast at 1:00PM Eastern on Sunday!
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
Linux and Unix
Tag Cloud
access acer asus bios bsod computer crash desktop driver drivers error ethernet excel freeze gaming hard drive hardware hdmi internet laptop malware memory modem monitor motherboard network printer problem ram registry router security slow software sound toshiba trojan ubuntu 11.10 uninstall usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Operating Systems > Linux and Unix >
Ubuntu server; running non blocking commands

Reply  
Thread Tools
cassamine's Avatar
Member with 188 posts.
 
Join Date: Nov 2002
Location: New Delhi
12-May-2009, 05:55 AM #1
Question Ubuntu server; running non blocking commands
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
Code:
command1
command2 
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's Avatar
Distinguished Member with 21,345 posts.
 
Join Date: Sep 2003
Location: -71.45091, 42.27841
14-May-2009, 10:46 AM #2
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
__________________
The independence created by philosophical insight is - in my opinion - the mark of distinction
between a mere artisan or specialist and a real seeker after truth. - Einstein 1944
Imagination is more important than knowledge. - Einstein
cassamine's Avatar
Member with 188 posts.
 
Join Date: Nov 2002
Location: New Delhi
18-Jun-2009, 06:29 AM #3
Thumbs up Solved
Forgot to reply sooner..

That worked yaay

Thanks mates
tomdkat's Avatar
Computer Specs
Distinguished Member with 7,127 posts.
 
Join Date: May 2006
Location: S.F. Bay Area, CA
Experience: Intermediate
18-Jun-2009, 03:58 PM #4
Quote:
Originally Posted by lotuseclat79 View Post
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...
Reply

Tags
bash, cli, johl, non blocking, ubuntu server

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 11:23 PM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.