getting pid of process

hi all,

Is there a simple script anyone could through out to me, to find the pid of a process given the name. I actually need to bind this pid to a processor set. I would probably put these comamns in a shell script which would have.
a) kick start the executable
b) get the pid
c) bind it to a specific processor set

second question is, would anyone know a way of getting the process ID inside a java program?

PS: SORRY, I accidentally posted this in the wrong topic. Should have been under Scripting & shell.

man pgrep; man pidof

small test, seems to work:

root@mp-wst01 # poolcfg -c 'create pool pressy'
root@mp-wst01 # poolcfg -c 'create pset pressy-set'
root@mp-wst01 # poolcfg -c 'associate pool pressy (pset pressy-set)'
root@mp-wst01 # poolcfg -c 'modify pset pressy-set ( uint pset.min = 1 ; uint pset.max = 2 )'
root@mp-wst01 # pooladm -c
root@mp-wst01 # ps -ef | grep syslogd
    root   489     1   0   Mar 19 ?           0:02 /usr/sbin/syslogd
root@mp-wst01 # poolbind -q 489
489     pool_default
root@mp-wst01 # poolbind -p pressy -i pid `pgrep syslogd`
root@mp-wst01 # poolbind -q 489
489     pressy
root@mp-wst01 #

gP

pressey..
i am not sure if it has to be done in such a complicated way, but I did it as below

id = ps -ef | grep myprocessname | grep -v grep | cut -c5-c10

psrset -b processor_set_id $id

this worked...
you can give psrset -q to see the bindings

hmm, nice found.... didn't know that...

i am always working with pools to get more flexibility between the processor sets... like setting an own scheduler class for the sets or creating a "cpu-load balancing" between several sets....

btw:
short form of you 2 lines could be:
# psrset -b processor_set_id `pgrep myprocessname `

regards pressy

pressy..
is there a way I could inhinit a few of my processes to go on to a particular processor_set_id?
I mean I have a box with 24virtual cpus and have created 2 processor sets.
One with 3 and the other with 20.

I want the processor set with 20 vcpus to be running uninterrupted for a particular process. I have already bound them to the process. But while they sleep, probably some other processes stell the cpus. Can I avoid it?

sounds like you having fun with your 6core niagara Tx000 :wink:

but yes, and that's the reason why i am using pools.... with the solaris resource management you can start processes inside a project and that project can use a defined pool with the "project.pool" attribute and that pool is associated to a processor set... :eek: :wink:

but why don't you use zones/container? that would be the best way to isolate the processes against each other and bind the CPUs to their environment...

gP

LOL..
u caught me there..
any good online material for me to know more about these zone thingies?

that's a very good explanation with good examples about zones and resource management with containers from Brendan Gregg

regards pressy

thanks pressy and reborg..
will try to adopt this one of these days.