Operating System - HP-UX
1752284 Members
5040 Online
108786 Solutions
New Discussion юеВ

Assign a process to a processor

 
SOLVED
Go to solution
Matteo Pignoni
Advisor

Assign a process to a processor

Hi!
Is it possible to assign a process to a processor?
For example if I have a server with 4 processor, can I decide to execute a process only in the CPU #3 ?
Thanks.
6 REPLIES 6
James R. Ferguson
Acclaimed Contributor
Solution

Re: Assign a process to a processor

Hi:

Take a look at PRM (Process Resource Manager) for this. Here's a link to the guide:

http://docs.hp.com/hpux/onlinedocs/B8733-90005/B8733-90005.html

...JRF...
Patrick Wallek
Honored Contributor

Re: Assign a process to a processor

Bill McNAMARA_1
Honored Contributor

Re: Assign a process to a processor

This one is free.. instructions below

Later,
Bill


=======================================================================
Program to set processor affinity: (setproc.c)
-------------------------------------------------------------------------

#include
#include
#include
#include
#include

main(argc,argv)
int argc;
char *argv[];
{
gid_t sgid;
int i;
int pid;

if (argc < 2) {
printf("Usage: setproc spunum pid0 [pid1 ... pidn]\n");
exit(1);
}
sgid = atoi (argv[1]);
i = argc;
printf("Attempting to set process affinity for processor %d\n",
sgid);
while (i-- >2) {
pid = atoi(argv[i]);
if ((sgid = SETPROCESS(sgid, pid)) < 0)
perror("setprocess failed");
printf ("processor %d pid = %d\n", sgid, pid);
}
}
-------------------------------------------------------------------------


Compile the above program with

cc -o setproc setproc.c

The following shell script can be used to test that processor affinity
is working correctly:
--------------------------------------------------------------------
#!/bin/ksh

echo process id = $$
i=1

while [ "$i" -lt 10000 ]
do
echo " $i\r\c"
i=`expr $i + 1`
sleep 1
done
--------------------------------------------------------------------

You can start an instance of this script and use the setproc program on a
dual processor system to switch processes between processors. You should
run this on a seperate terminal since it will send the count to the
terminal every second.

You can then use the setproc program to move the process between
processors.

Usage:

setproc 0

to force to process to processor 0, or use

setproc 1

to force process to processor 1, etc.


It works for me (tm)
John Bolene
Honored Contributor

Re: Assign a process to a processor

As Bill wisely said, you can dedicate a process to a processor, but you must have access to the source code and be able to compile it.

PRM is the only way that I know how to do it if you only have an executable binary file.
It is always a good day when you are launching rockets! http://tripolioklahoma.org, Mostly Missiles http://mostlymissiles.com
Carsten Krege
Honored Contributor

Re: Assign a process to a processor

With PRM you CANNOT force a process to run on a specific CPU. PRM can be used to ensure that a process (specifically a PRM group consisting of one ore more processes) cannot use more than a specific percentage of the total CPU resource (in times of high workload). The processes are not forced to run on a specific CPU though. THis would break many programs.

This can only be achieved with a program like Bill uses and which can force any PID to run on one specific CPU (ie you don't need the programs source), done by SETPROCESS which is a mpctl() system call.

Carsten
-------------------------------------------------------------------------------------------------
In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move. -- HhGttG
John Bolene
Honored Contributor

Re: Assign a process to a processor

Darn, every once in awhile you make a mistake.
Looks like this is my day.
I'll go to the doghouse for the rest of the day.
It is always a good day when you are launching rockets! http://tripolioklahoma.org, Mostly Missiles http://mostlymissiles.com