Less known Solaris Features: Resource Management - Part 2: How to work with Tasks and Projects
Even when you never heard of constructs like tasks and projects you already use them, as there are a few projects installed per default. For example whenever you log into your system as a regular user, all you do is part of the project
default because your user is member of this project:
When you assume the privileges of the root user you work as a member of the user.root project.
Let´s have another look at the alread running processes of your system.
As you see from the output of
ps you already use some projects, that are default on every Solaris system. And even the concept of task is in use right now. Whenever a user log into a Solaris system, a new task is opened. Furthermore you will see, that all your services started by the Service management facility have their own own task id. The SMF starts every service as a new task.
A freshly installed system has already this pre-defined projects:
Okay, but how do we create our own projects? It´s really easy:
We created the project
testproject with the project id
1000. Then we modified it by adding informations to the comment field. After this, we´ve deleted the project.
A practical example
Okay, i will use a practical example, now. We working as an administrator at the Unseen University. We´ve got a new system and want to create the users.
Looks familiar? I´ve omitted to set the password here. But of course you have to set one. Now we create some projects for two classes:
Okay. This projects have no users. We assign the project to our users.
Like roles this assignments are stored in the file
su to the user alice and check for the project assignment:
As configured the user
alice is assigned to the project
class2005. When we look into the process table, we can check the forth columns. All processes owned by alice are assigned to the correct project.
Okay, obviously our teachers want their own projects: You can configure this on two ways. You can can configure it by hand, or create a project beginning with
user. and ending with the username. We use the second method in this example.
Now we check for the project:
Et voila! We don´t have to assign the project explicitly. It´s done automagically by the system. The logic behind the automatic assigning of the project to a user is simple:
- If the name of the project is defined by adding the
projectuser attribute, use the assigned project as the default for the user.
- If it´s not defined with the user, look for a project beginning with
user.and ending with the name of the user and use it as default project. For example:
- If there no such project, search for a project beginning with
group.and ending with the name of the group of a user and use it as default project. For example:
- If there´s no group with this name, use the project "default" as the default project.
But how do you create a task? You don´t have to configure tasks! A task is created automatically by the system in certain events. Those events are:
Okay, let´s start a sleep in a new task:
Okay, when you look at the process table now, you will see the different taskid in the fifth column:
But you can use the newtask command to assign a different project, too. At first we create another project. We work at the Large Hadron Collider project, thus we call it
Hey, not this fast! You have to be a member of the project to add a task to a project. Without this hurdle it would be too easy to use the resources of different project ;) Okay, let´s add the user
einstein to the group lhcproject again.
Now we can try it again:
$ newtask -p lhcproject sleep 1000&Voila, the sleep runs within a different project.
$ ps -ef -o pid,user,zone,project,taskid,args | grep "einstein"
777 einstein global user.einstein 78 sh
817 einstein global lhcproject 80 sleep 1000
819 einstein global user.einstein 78 ps -ef -o pid,user,zone,project,taskid,args
818 einstein global user.einstein 78 grep einstein
Why do i need all this stuff?But why is all this stuff important for Resource Management? While it´s possible to put resource management onto a single process, this isn´t a sensible choise most of the time. Your workload consists out of multiple services out of multiple processes and it would be more complex to configure resource managment to each of this processes. With the concepts of projects and tasks you can assign those limits to a group of processes.