Shell script to bind my job to half the number of vCPUs in Solaris

I would like to launch a script but bind it to half the number of vCPUs
only so that the max CPU utilization is 50-60% max

So I'll need a Shell script to

a) check how many vCPUs a VM has (we can have 1 to 16, incl odd number) so
   I read something like "psrinfo |grep -c on-line" will help: grab the number from
   the right-most  column in the output

b) if it's one vCPU, then run the command in nice mode & bind it:
     nice /path/scriptname
     sed `ps -ef |grep scriptname | grep -v grep` <== to get the pid#
     pbind -b 0 pid#

c) if more than one vCPU, then pbind to half the number of processors/vCPU & 
    run the command.  If there's odd number, say 5, then pbind to 3 vCPUs

    & the script needs to create a processor set before doing the pbind:

d) launch my script which will be run within that vCPU or set of vCPUs
   in nice mode which will self-abort if it runs for more than 8 hrs:
     timeout -k 1m 28800s nice /path/myscript
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Solaris does not allow to split CPU like AIX or Linux.
sunhuxAuthor Commented:
The following is for Solaris:

So how is it that you don't find it?
AIX (WLM) and Linux (cgroups) allows a process to be jailed in 10% of CPU if you like. This is not excatlry pbind/bindproc.
For your antivirus scenario it is really of value to add random sleep to scan, centrally managed (read: expensive) AV products allow doing it.
If you still have problems with IO saturation we can find solution for that too.
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

nociSoftware EngineerCommented:
you may get away with f.e. Make usingit in parrallel more
with 1 + (half of #vCPU's) as the limit on the number of jobs.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
I am pretty sure it is IO saturation in vmware, can you record iostat 30 while scan is running , i suspect IO wait 90% of CPU time
nociSoftware EngineerCommented:
In that case more cpu intensive work, ie.not doing IO, can be loaded onto the system.
sunhuxAuthor Commented:
Don't understand what Noci is saying:
get away with f.e. Make usingit in parrallel more
with 1 + (half of #vCPU's) as the limit

I heard in Solaris 10, we can use "project" facility to restrict amount
(in terms of %) that a job can consume but this project facility is
rather complex to configure & use, IMHO
sunhuxAuthor Commented:
Now got another challenge:
I have 50 odd Solaris 10 x86 with only 1 vCPU & running this command line
AV scan (no central management) will chew up practically 100% of the CPU.

Without using "project" facility in Solaris, is there any other way to limit its
CPU utilization?

IO saturation is not my current concern (as least not yet)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.