You say it is a daemon, so I suppose it is started as root, and you want to change to a different user ("drop root privileges" as they say) to increase security of your program.
You can do that like below. Though this is in C, it largely (if not entirely) applies to C++.
Code:
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int main()
{
uid_t uid; /* user to change to */
gid_t gid; /* group to change to */
/* Change these to your needs */
uid = 65534;
gid = 65534;
/* ... other things ... */
/* Become daemon */
if (daemon(0,0) < 0) {
perror("Error becoming daemon");
return 1;
}
/* Become non-root */
setregid(gid, gid);
if (getgid() == 0 || getegid() == 0) {
perror("Could not drop GID root");
return 1;
}
setuid(uid);
if (getuid() == 0 || geteuid() == 0) {
perror("Could not drop UID root");
return 1;
}
/* Start doing work here */
/* ... */
return 0;
}