Skip to content

Instantly share code, notes, and snippets.

@AlexsJones
Created October 3, 2012 12:31
Show Gist options
  • Select an option

  • Save AlexsJones/3826692 to your computer and use it in GitHub Desktop.

Select an option

Save AlexsJones/3826692 to your computer and use it in GitHub Desktop.
int kill_spawn()
{
pid_t parent = getpid();
//Isn't this an ugly way of doing ATOI, but hey thats the way it goes
stringstream parent_string;
parent_string << parent;
cout << "Current process ID is : " << parent << endl;
system("ps -ax | grep launch_pad > /tmp/process.tmp");
ifstream fs("/tmp/process.tmp");
string line;
while(fs.good())
{
getline(fs,line);
if(line != "")
{
vector<string> chopper = jnx_string::split(line," ");
cout << chopper[0] << endl;
if(chopper[0] != parent_string.str())
{
stringstream ss;
ss << "kill -9 " << chopper[0];
system(ss.str().c_str());
}
}
}
system("rm /tmp/process.tmp");
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment