Skip to content

Instantly share code, notes, and snippets.

@a-square
Created April 5, 2012 08:15
Show Gist options
  • Save a-square/2308949 to your computer and use it in GitHub Desktop.
Save a-square/2308949 to your computer and use it in GitHub Desktop.
A program that allows you to run gui apps from the console without getting all of its output. E.g.: cd ~/work/a/b/c/; run ./gui-app param
#include <unistd.h>
#include <sys/types.h>
#include <sys/ioctl.h>
int main (int argc, char **argv)
{
pid_t pid;
int fd;
/*
* parent terminates
* child gets rid of its tty and then shift-runs its arguments
*/
pid = fork();
if (pid < 0) {
return 1;
} else if (pid == 0) {
/* close standard files */
close (0); close (1); close (2);
/* detach the tty */
fd = open ("/dev/tty", 0);
ioctl (fd, TIOCNOTTY);
close (fd);
/* execute the provided program */
execvp (argv[1], argv + 1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment