The key points of the example include the following:
This example is similar to the example shown in Set pool.comment Property and Add New Property.
Use bcopy(), rather than buffer swapping as in List all the Value-action Pairs for a Specific Resource Control.
To change the resource control value, call setrctl() with the RCTL_REPLACE flag. The new resource control block is identical to the old resource control block except for the new control value.
rctlblk_set_value(blk1, nshares); if (setrctl("project.cpu-shares", blk2, blk1, RCTL_REPLACE) != 0)
The example gets the project's CPU share allocation, project.cpu-shares, and changes its value to nshares.
/* Omit return value checking/error processing to keep code sample short */ blk1 = malloc(rctlblk_size()); getrctl("project.cpu-shares", NULL, blk1, RCTL_FIRST); my_shares = rctlblk_get_value(blk1); printout_my_shares(my_shares); /* if privileged, do the following to */ /* change project.cpu-shares to "nshares" */ blk1 = malloc(rctlblk_size()); blk2 = malloc(rctlblk_size()); if (getrctl("project.cpu-shares", NULL, blk1, RCTL_FIRST) != 0) { perror("getrctl failed"); exit(1); } bcopy(blk1, blk2, rctlblk_size()); rctlblk_set_value(blk1, nshares); if (setrctl("project.cpu-shares", blk2, blk1, RCTL_REPLACE) != 0) { perror("setrctl failed"); exit(1); }