ChorusOS 5.0 Application Developer's Guide

Commonalities Between Processes and Actors

Processes and actors are similar in many ways. In most instances, the same functionality is available to both actors and processes. However, different system calls are required to obtain this functionality.

A process can be defined as an actor that uses the services of the POSIX API. Therefore, all processes are actors and have a capability KnCap. The reverse is not true, that is, not all actors are necessarily processes.

Processes are linked to the os/lib/libc.a library. Actors such as drivers should never be linked to the os/lib/libc.a library and therefore cannot be processes.

The rsh targetname aps command enables a list of all processes running on a target to be displayed.


Note -

To the microkernel, all entities running on the system (both actors and processes) are actors.


Actor and Process Identification

Every actor, whether it is a boot actor or a dynamically loaded actor, is uniquely identified by an actor capability (KnCap). When several ChorusOS operating systems are functioning over a network in a distributed system, these capabilities are always unique through space and time. An actor may identify itself with the predefined capability:

K_MYACTOR

The microkernel attributes a capability (KnCap) to each actor. A process is also identified by a local process identifier (PID). This identifier is displayed when the process is executed manually.

User and Supervisor Processes and Actors

Applications are classified as either supervisor or user applications. This classification is called the privilege of the application. User applications have separate and protected address spaces so that they cannot overwrite each other's address spaces. Supervisor applications use a common (but partitioned) address space. Depending on the underlying hardware, a supervisor application can execute privileged hardware instructions (such as initiating I/O), while a user application cannot.

The ChorusOS operating system offers a method to determine dynamically whether an application is currently running as a user or supervisor process or actor. The example below demonstrates how to find the privilege of an actor. The same call can be used to find the privilege of a process.

#include <chorus.h>
int actorPrivilege (	KnCap*					actorCap,
  						 	KnActorPrivilege*		old,
								KnActorPrivilege*		new); 	

In the previous example, if actorCap is set to the name of an actor, you can use this API to obtain the privilege of the named actor. If actorCap is set to the predefined value K_MYACTOR, you can obtain the privilege of the current actor. If the actor is a privileged (supervisor or system) actor, this call can also be used to change the privilege of an actor dynamically from user to system or vice versa.

The following example illustrates the use of the actorPrivilege(2K) service. It is a small program that retrieves its privilege without trying to modify it. The program prints one message if the actor is running as a user actor, and another if it is running as a supervisor actor.

KnActorPrivilege is the type defined by the ChorusOS operating system to handle the type of an actor. The defined values for the actor type are:


Example 3-1 Getting Actor Privilege

#include <stdio.h>
#include <chorus.h>
int main(int argc, char** argv, char** envp)
{
   KnActorPrivilege    actorP;
   int                 res;
       /* Get actor's privilege */
   res = actorPrivilege(K_MYACTOR, &actorP, NULL);
   if (res != K_OK) {
      printf("Cannot get the privilege of the actor, error %d\n", res);
      exit(1);
   }
   if (actorP == K_SUPACTOR) {
      printf("This actor is running as a supervisor actor\n");
   } else {
      printf("This actor is running as a user/system actor\n");
   }
   exit(0);
}