From: Bela Lubkin <belal@sco.com> Subject: Re: how to force running on a selected cpu on smp machine Date: Tue, 19 Nov 2002 15:18:32 GMT References: <3DD517A1.E7641423@oce.de>
<20021115103759.H3983@mammoth.ca.sco.com>
<3DD69630.6000601@t-online.de>
<20021116111309.M3983@mammoth.ca.sco.com>
<20021116113134.N3983@mammoth.ca.sco.com>
<3DDA0188.56DAE28@oce.de> Carsten Hammer wrote: > For a shell script solution: > > Has anybody ever used lockpid to *start* a prozess on a certain cpu? It should be > possible using a tricky wrapper script around it by delaying execution of a > forked process and using lockpid in the meantime, isnt it?
It looks like you don't even have to be very tricky:
# sh -c 'lockpid -l 2 $$; while :; do :; done' &
# sh -c 'lockpid -l 2 $$; while :; do :; done' &
# mpstat
You'll see that CPU 2 is 100% busy, CPU 1 isn't. In each case, '$$' is
the PID of the respective new process. The "while" is being run in the
same process that got locked. Next:
# sh -c 'lockpid -l 2 $$; awk "BEGIN { while(1); }"'&
# sh -c 'lockpid -l 2 $$; awk "BEGIN { while(1); }"'&
# mpstat
Two CPUs will be lit up. `awk` is a subprocess of the locked process,
and locking doesn't carry across to children.
Finally,
# sh -c 'lockpid -l 2 $$; exec awk "BEGIN { while(1); }"'&
# sh -c 'lockpid -l 2 $$; exec awk "BEGIN { while(1); }"'&
# mpstat
Now `awk` is being exec'd within the same process that was locked.
exec(S) does not clear CPU locks.
>Bela<
PS: I was testing this on a 4-CPU box, so I always had spare CPUs to use
for killing these runaways... Except once when I mistakenly locked my
shell onto the same CPU I was abusing. Then things got pretty difficult
for a while. My mistake:
# (lockpid -l 2 $$; while :; do :; done) &
I was using ksh -- not sure if sh would do the same -- '$$' here was the
PID of the parent shell, so I got locked onto CPU 2. Then I ran a
correct statement, locking a runaway onto CPU 2 ... and shell
interaction got really slow. It might be good to use `nice` somewhere
in the equation to make the runaways back off. But I always get
confused about the syntax of `nice`...
Have you tried Searching this site?
Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates
This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.
Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.
Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.
We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.
Click here to add your comments
Don't miss responses! Subscribe to Comments by RSS or by Email
Click here to add your comments
If you want a picture to show with your comment, go get a Gravatar