Hi everyone!
Have someone ever seen something about the command posix_spawn?
I want to spawn a new process using this command because it’s more flexible.You can set things just like below:
-
posix_spawnattr_setrunmask:
Sets, in theory, the CORE processor that will run the spawned process. -
posix_spawnattr_setschedparam:
Sets the parameters of the attributes of the spawned process. -
posix_spawnattr_setschedpolicy:
Sets the parameters of the scheduling policy attribute of the spawned process. -
posix_spawnattr_setstackmax:
Sets the maximum stack size for the spawned process.
Follows the code below:
char * _ExecutablePath[] = { "/usr/sbin/qconn", NULL };
parentProcessID = getpid();
printf("Parent Process ID: %d\n", parentProcessID);
fflush(stdout);
_RestrictSched_p.sched_priority = 20;
status = posix_spawnattr_setrunmask(&_RestrictAttrp, uint32RunMask);
if (status)
handle_error_en(status, "posix_spawnattr_setrunmask");
status = posix_spawnattr_setschedparam(&_RestrictAttrp, &_RestrictSched_p);
if (status)
handle_error_en(status, "posix_spawnattr_setschedparam");
status = posix_spawnattr_setschedpolicy(&_RestrictAttrp, SCHED_RR);
if (status)
handle_error_en(status, "posix_spawnattr_setschedpolicy");
status = posix_spawnattr_setstackmax(&_RestrictAttrp, uint32Size);
if (status)
handle_error_en(status, "posix_spawnattr_setstackmax");
status = posix_spawn(&childProcessID, _ExecutablePath[0], &fileActions,
&_RestrictAttrp, _ExecutablePath, NULL);
if (status)
handle_error_en(status, "posix_spawnp");
printf("Child Process ID: %d\n", childProcessID);
killpg(getpid(), SIGKILL);
Thanks in advance!