Solaris Containers: Resource Management and Solaris Zones Developer's Guide

Chapter 2 Projects and Tasks

The chapter discusses the workload hierarchy and provides information about projects and tasks. The following topics are covered:

Overview of Projects and Tasks

The Solaris Operating System uses the workload hierarchy to organize the work being performed on the system. A task is a collection of processes that represents a workload component. A project is a collection of tasks that represents an entire workload. At any given time, a process can be a component of only one task and one project. The relationships in the workload hierarchy are illustrated in the following figure.

Figure 2–1 Workload Hierarchy

Diagram shows the relationships among projects, tasks,
and processes.

A user who is a member of more than one project can run processes in multiple projects at the same time. All processes that are started by a process inherit the project of the parent process. When you switch to a new project in a startup script, all child processes run in the new project.

An executing user process has an associated user identity (uid), group identity (gid), and project identity (projid). Process attributes and abilities are inherited from the user, group, and project identities to form the execution context for a task.

For an in-depth discussion of projects and tasks, see Chapter 2, Projects and Tasks (Overview), in System Administration Guide: Solaris Containers-Resource Management and Solaris Zones. For the administration commands for managing projects and tasks, see Chapter 3, Administering Projects and Tasks, in System Administration Guide: Solaris Containers-Resource Management and Solaris Zones.

/etc/project File

The project file is the heart of workload hierarchy. The project database is maintained on a system through the /etc/project file or over the network through a naming service, such as NIS or LDAP.

The /etc/project file contains five standard projects.

system

This project is used for all system processes and daemons.

user.root

All root processes run in the user.root project.

noproject

This special project is for IPQoS.

default

A default project is assigned to every user.

group.staff

This project is used for all users in the group staff.

To access the project file programmatically, use the following structure:

struct project {
  char      *pj_name;       /* name of the project */
  projid_t   pj_projid;     /* numerical project ID */
  char      *pj_comment;    /* project comment */
  char     **pj_users;      /* vector of pointers to project user names */
  char     **pj_groups;     /* vector of pointers to project group names */
  char      *pj_attr;       /* project attributes */
};

The project structure members include the following:

*pj_name

Name of the project.

pj_projid

Project ID.

*pj_comment

User-supplied project description.

**pj_users

Pointers to project user members.

**pj_groups

Pointers to project group members.

*pj_attr

Project attributes. Use these attributes to set values for resource controls and project pools.

Through project attributes, the resource usage can be controlled. Four prefixes are used to group the types of resource control attributes:

For the complete list of resource controls, see resource_controls(5).

Project and Task API Functions

The following functions are provided to assist developers in working with projects. The functions use entries that describe user projects in the project database.

endprojent(3PROJECT)

Close the project database and deallocate resources when processing is complete.

fgetprojent(3PROJECT)

Returns a pointer to a structure containing an entry in the project database. Rather than using nsswitch.conf, fgetprojent() reads a line from a stream.

getdefaultproj(3PROJECT)

Check the validity of the project keyword, look up the project, and return a pointer to the project structure if found.

getprojbyid(3PROJECT)

Search the project database for an entry with the number that specifies the project ID.

getprojbyname(3PROJECT)

Search the project database for an entry with the string that specifies project name.

getprojent(3PROJECT)

Returns a pointer to a structure containing an entry in the project database.

inproj(3PROJECT)

Check whether the specified user is permitted to use the specified project.

setproject(3PROJECT)

Add a user process to a project.

setprojent(3PROJECT)

Rewind the project database to allow repeated searches.

Code Examples for Accessing project Database Entries


Example 2–1 Printing the First Three Fields of Each Entry in the project Database

The key points for this example include the following:

#include <project.h>

struct project projent;
char buffer[PROJECT_BUFSZ]; /* Use safe buffer size from project.h */
	...
struct project *pp;

setprojent();  /* Rewind the project database to start at the beginning */

while (1) {
   pp = getprojent(&projent, buffer, PROJECT_BUFSZ);
	  if (pp == NULL)
          break;
    printf("%s:%d:%s\n", pp->pj_name, pp->pj_projid, pp->pj_comment);
		...
};

endprojent();   /* Close the database and free project resources */


Example 2–2 Getting a project Database Entry That Matches the Caller's Project ID

The following example calls getprojbyid() to get a project database entry that matches the caller's project ID. The example then prints the project name and the project ID.

#include <project.h>

struct project *pj;
char buffer[PROJECT_BUFSZ]; /* Use safe buffer size from project.h */

main()
{
   projid_t pjid;
   pjid = getprojid();
   pj = getprojbyid(pjid, &projent, buffer, PROJECT_BUFSZ);
   if (pj == NULL) {
       /* fail; */
   }
   printf("My project (name, id) is (%s, %d)\n", pp->pj_name, pp->pj_projid);
}

Programming Issues Associated With Projects and Tasks

Consider the following issues when writing your application: