문제

I have a process which uses select to poll the stdin file descriptor, when I run it from console it works fine. After I added this process under cron I see that the output indicates a problem calling select with stdin under cron. Is there a way to workaround this when using cron and make the process think there is an stdin file descriptor which receives nothing?

도움이 되었습니까?

해결책

So what I did was to check /proc/self/fd/0, in case it's not /dev/pts/something I skip the select command. Check your fd 0 using something like this

bool rc = true;
char linkName[256];
const char* fd0 = "/proc/self/fd/0";
const char* devPts = "/dev/pts";
struct stat sb;
lstat(fd0, &sb);
readlink(fd0, linkName, sb.st_size + 1);
linkName[sb.st_size] = '\0';
if (strncmp(linkName, devPts, sizeof(devPts)) != 0)
{
    std::cout << "The application's stdin file descriptor doesn't point to /dev/pts/XXX, input will be ignored" << std::endl;
    rc = false;
}
return rc;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top