LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-22-2009, 02:56 AM   #1
jchambers
Member
 
Registered: Aug 2007
Location: California
Distribution: Debian
Posts: 127

Rep: Reputation: 15
Run multiple apps at once without waiting..?


Hello.

I am not sure how to explain this...
Below is a for loop that calls a function for loop. I am trying to somehow not wait till the function loop finishes before the next call is made.

So as soon as the doit "A" is called then doit "B" is called without waiting. Is this possible or is there a workaround for this?

The goal is to run multiple apps at once for an hour each. So I need to create a loop that will start them without waiting. Also the app have dynamic info for each so I can't make a static cron entry.


Example:
Code:
#!/bin/sh

my_array=(A B)

function doit()
{
	for ((i=0;i<100;i+=1)); do
		echo ${i} > /tmp/${1}
		sleep 1
	done
}

for ((i=0;i<${#my_array[@]};i+=1)); do
	doit ${my_array[${i}]}
done

exit
 
Old 04-22-2009, 03:22 AM   #2
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612
doit ${my_array[${i}]} &
 
Old 04-22-2009, 06:18 AM   #3
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
put an ampersand & after any shell line
and it will operate in the background.


or usually in a bash shell, start a command,
press CTRL-Z will stop it, and bg will put it in the background.
fg will bring it back to the foreground.

nohup will run it independently from the terminal
so you can log out.

at will do similar to nohup but will mail you any terminal output on completion.
 
Old 04-22-2009, 11:14 AM   #4
jchambers
Member
 
Registered: Aug 2007
Location: California
Distribution: Debian
Posts: 127

Original Poster
Rep: Reputation: 15
Thank you both for the reply.

Espeically bigearsbilly for taking the time to explain why.

It does exactly what I need now.

Jon
 
Old 04-23-2009, 06:25 AM   #5
jisjis
LQ Newbie
 
Registered: Apr 2009
Posts: 18

Rep: Reputation: 0
The & command is your friend ...



Linux

Last edited by jisjis; 04-26-2009 at 04:42 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple apps and LIRC colbert Linux - Software 1 08-01-2010 02:29 AM
Cannot have sound in multiple apps? Rexx Magnus Debian 1 09-04-2008 08:57 AM
Hard Drive Problems: timeout waiting for DMA; error waiting for DMA mintee Linux - Hardware 10 09-21-2007 05:06 AM
My browser, all day today: 'waiting for linuxquestions.org...' ..waiting.. waiting .. GrapefruiTgirl LQ Suggestions & Feedback 18 05-25-2007 05:35 AM
When I run rpm -Uvh it says "warning: waiting for transaction lock" Niceman2005 Linux - Software 5 11-12-2004 07:47 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration