As I said the process of starting a task and obtaining it's PID is
working. The reason I need the PID was for some level of task
managment. In particular, one thing I need to be able to do is pause
and continue these tasks using SIGSTOP/SIGCONT. There are other things
also but this one seems to be giving me problems right now. When I
send SIGSTOP to one of these processes, it EXITS instead of pausing.
That same task pauses and continues just find when I send these
signals from a shell via "kill -s SIGSTOP/SIGCONT pid". In fact it
seems that if I send the signals from a different task (one that
didn't actually create the process) it also? Why is the task that
created the process not able to "correctly" send the SIGSTOP signal to
it? Sample code:
tskmgt.c : task that starts and attempts to pause another task
int32_t main(int argc, char **argv)
{
pid_t pid;
const char *path = "/home/markh/test/tsttsk";
char *arg = 0;
pid = fork();
if (pid == 0) { // then I am the new task
execv(path, &arg);
} else {
printf("PID of new task = %d\n", pid);
}
sleep(5);
printf("Sending SIGSTOP to pid %d\n", pid);
if (kill(pid, SIGSTOP) != 0)
perror("Failed to send SIGSTOP: ");
return 0;
}
tsttsk.c:
int32_t main(int argc, char **argv)
{
FILE *fd;
const char *path = "/var/log/srtl.log";
const char *mode = "w+";
fd = fopen(path, mode);
if (fd < 0) {
perror("fopen of /var/log/srtl.log failed: ");
return 1;
}
while (1) {
sleep(1);
fprintf(fd, "tsttsk is running\n");
fflush(fd);
}
return 0;
}
I have not yet attempted to use posix_spawn BTW. I would like to
understand why this doesn't work first.
Regards
Mark