CPU optimization


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting CPU optimization
# 1  
Old 11-26-2012
CPU optimization

hi guys ,

I have 10 scripts
suppose 1.sh , 2.sh ,3.sh ,4.sh ......10.sh
each takes some time ( for instance 2 minutes to 40 minutes )

my server can run around 3-4 files at a time
suppose,
1.sh ,
2.sh ,
3.sh
are running currently now as soon as ANY ONE of the gets finished i want to run next process i.e. 4.sh automatically & so on till 10.sh
there is no dependency in these scripts ....

plz help
# 2  
Old 11-26-2012
Hi.

The command xargs can address such problems. It is found on almost every modern system. See man xargs for details, and, if you run into problems with your experiments, let us know.

Another possibility is the more capable (and complex) parallel, but it's more likely that your system has xargs.

Best wishes ... cheers, drl
This User Gave Thanks to drl For This Post:
# 3  
Old 11-27-2012
hi
tnx to u i have learned xargs command..
bt u knw d problem is not with how many scripts (arguments here ) i run at a time..
The problem is i cant run the next process before the previous process gets finished and CPU is free....
can u plz suggest how will i use 'PARALLEL' command in the given case..
My each script will run and will give o/p as 'procedure executed successfully'
can we use this o/p as some trigger?
# 4  
Old 11-27-2012
Hi.

First, please follow the rules, among them:
Code:
(9) Edit your posts if you see spelling or grammar errors (don't write in cyberchat or cyberpunk style). English only.

See The UNIX and Linux Forums - Forum Rules

Second, try running the command:
Code:
seq 10 20 | xargs -n 1 -P 3 sleep &

then monitor the processes continuously by repeatedly entering:
Code:
ps -f

and you should see that xargs runs several processes, adhering to the limit of 3. The command was suggested by An easy way to run many tasks in parallel at Xaprb

The man xargs page contains some examples as well as a description of the options.

If your repository does not have parallel for you to easily install, see GNU Parallel - GNU Project - Free Software Foundation

Good luck with your experiments.

Best wishes ... cheers, drl

Last edited by drl; 11-27-2012 at 08:18 AM..
# 5  
Old 11-28-2012
Hey ,
thank you
but I got it using a different approach

I used counter variable to count running using PID ..

then i executed next processes using loop , condition for loop being :
if ( count < allowed )
run next ....

by the way , thank you Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Code optimization

Hi all I wrote below code: #!/bin/sh R='\033 do you have any idea how to optimize my code ? (to make it shorter eg.) (11 Replies)
Discussion started by: primo102
11 Replies

2. UNIX for Dummies Questions & Answers

Is it possible to combine multiple CPU to act as a single CPU on the same server?

We have a single threaded application which is restricted by CPU usage even though there are multiple CPUs on the server, hence leading to significant performance issues. Is it possible to merge / combine multiple CPUs at OS level so it appear as a single CPU for the application? (6 Replies)
Discussion started by: Dissa
6 Replies

3. Programming

Make file optimization

Hi , I need some help on optmizing the make file. I have the below scenario. SOUTHERN_XITEM_PROGS=\ sfmxitem.rel \ sfqxitem.rel SOUTHERN_XITEM_DEPS= southern_xitem.c SUPERSVU_XITEM_PROGS=\ su3xitem.rel SUPERSVU_XITEM_DEPS= supersvu_xitem.c $(SOUTHERN_XITEM_PROGS) : $$@.o... (1 Reply)
Discussion started by: angelinrajeesha
1 Replies

4. Shell Programming and Scripting

sed optimization

I have a process using the following series of sed commands that works pretty well. sed -e 1,1d $file |sed 1i\\"EHLO Broadridge.com" |sed 2i\\"MAIL FROM:${eaddr}"|sed 3i\\"RCPT TO:${eaddr}"|sed 4i\\"DATA"|sed 5s/.FROM/FROM:/|sed 6s/.TO/TO:/|sed 7,7d|sed s/.ENDDATA/./|sed s/.ENDARRAY// >temp/$file... (1 Reply)
Discussion started by: njaiswal
1 Replies

5. Shell Programming and Scripting

AWK optimization

Hello, Do you have any tips on how to optimize the AWK that gets the lines in the log between these XML tags? se2|6|<ns1:accountInfoRequest xmlns:ns1="http://www.123.com/123/ se2|6|etc2"> .... <some other tags> se2|6|</ns1:acc se2|6|ountInfoRequest> The AWK I'm using to get this... (2 Replies)
Discussion started by: majormark
2 Replies

6. Solaris

Multi CPU Solaris system shows 100% CPU usage.

Hello Friends, On one of my Solaris 10 box, CPU usage shows 100% using "sar", "vmstat". However, it has 4 CPUs and prstat and glance are not showing enough processes to justify high CPU utilization. ========================================================================= $ prstat -a ... (4 Replies)
Discussion started by: mahive
4 Replies

7. Shell Programming and Scripting

script optimization

:o Hi, I am writing a script in which at some time, I need to get the process id of a special process and kill it... I am getting the PID as follows... ps -ef | grep $PKMS/scripts | grep -v grep | awk '{print $2 }'can we optimize it more further since my script already doing lot of other... (3 Replies)
Discussion started by: vivek.gkp
3 Replies

8. UNIX for Dummies Questions & Answers

how to get persistant cpu utilization values per process per cpu in linux (! top,ps)

hi, i want to know cpu utilizatiion per process per cpu..for single processor also if multicore in linux ..to use these values in shell script to kill processes exceeding cpu utilization.ps (pcpu) command does not give exact values..top does not give persistant values..psstat,vmstat..does njot... (3 Replies)
Discussion started by: pankajd
3 Replies

9. UNIX for Dummies Questions & Answers

Help on optimization of the script

Hi, I have prepared script which is taking more time to process. find below script and help me with fast optimized script:- cat name.txt | while read line do name=$(echo $line| awk '{print $8}') MatchRecord=$(grep $name abc.txt | grep -v grep ) echo "$line | $MatchRecord" | awk... (2 Replies)
Discussion started by: aju_kup
2 Replies
Login or Register to Ask a Question