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

Set LWP Limit on Resource Control Blocks

In the following example, our application has set a privileged limit of 3000 LWPs that may not be exceeded. In addition, our application has set a basic limit of 2000 LWPs. When this limit is exceeded, a SIGXRES is sent to the application. Upon receiving a SIGXRES, our application might send notification to its child processes that might in turn reduce the number of LWPs the processes use or need.

/* Omit return value and error checking */

#include <rctl.h>

rctlblk_t *rcb1, *rcb2;

         * Resource control blocks are opaque
         * and must be explicitly allocated.
rcb1 = calloc(rctlblk_size());	

rcb2 = calloc(rctlblk_size());	

/* Install an RCPRIV_PRIVILEGED, v=3000: do not allow more than 3000 LWPs */
rctlblk_set_value(rcb1, 3000);
rctlblk_set_privilege(rcb1, RCPRIV_PRIVILEGED);
rctlblk_set_local_action(rcb1, RCTL_LOCAL_DENY);
setrctl("task.max-lwps", NULL, rcb1, RCTL_INSERT);

/* Install an RCPRIV_BASIC, v=2000 to send SIGXRES when LWPs exceeds 2000 */
rctlblk_set_value(rcb2, 2000);
rctlblk_set_privilege(rcb2, RCPRIV_BASIC);
rctlblk_set_local_action(rcb2, RCTL_LOCAL_SIGNAL, SIGXRES);
setrctl("task.max-lwps", NULL, rcb2, RCTL_INSERT);