Your main application can fork a child process, and then use execv() to execute your 'first' executable that validates the key.
The main application can check the exit status of the 'first' process using waitpid(). This call will block the main application from continuing until the 'first' process completes.
If the returned status is good (typically this is a value of 0), then you can do something similar to launch your 'second' process.
For example:
Code:
#include <iostream>
#include <cstring>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
int main(int argc, char** argv)
{
const char* licenseKey = "!@#123#@!";
pid_t keyval_pid = fork();
if (keyval_pid == 0)
{
// In child-process...
// Set up args to launch key-validation (i.e. 'first') process.
char** args = new char*[3];
args[0] = strdup("./first");
args[1] = strdup(licenseKey);
args[2] = 0;
execv(args[0], args);
}
// Await status from key-validation process.
int status;
waitpid(keyval_pid, &status, 0);
if (status != 0)
{
std::cerr << "Key is not valid." << std::endl;
return status;
}
std::cout << "Safe to launch second child process." << std::endl;
}