According to the question \" How to get Linux distribution name and version? \", to get the linux distro name and version, this works:
lsb_release -a
int writepipe[2];
if (pipe(writepipe) < 0) {
perror("pipe");
return 1;
}
int ret = fork();
if (ret < 0) {
perror("fork");
return 1;
}
else if (ret == 0) // child process
{
dup2(writepipe[1],1); // set writepipe[1] as stdout
// close fds
close(writepipe[0]);
close(writepipe[1]);
execlp("lsb_release","lsb_release","-a",NULL); //TODO: Error checking
}
else // parent process
{
int status;
waitpid(ret,&status,0); //TODO: Error checking
//do what you need
//read output of lsb_release from writepipe[0]
}
It works for me