File: fork_and_exec.c

package info (click to toggle)
ngetty 1.0-1
  • links: PTS
  • area: main
  • in suites: squeeze, wheezy
  • size: 304 kB
  • ctags: 207
  • sloc: ansic: 1,503; makefile: 236; sh: 109; asm: 100
file content (14 lines) | stat: -rw-r--r-- 331 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
extern char **environ;

void fork_and_exec(char *line) /*EXTRACT_INCL*/{
  if (line) {
    char *qq[4] = { "/bin/sh", "-c", line, 0 };
    pid_t pid=fork();
    if (pid==-1) return;
    if (pid==0) { execve(*qq,qq,environ); _exit(127); }
    waitpid(pid,0,0);
  }
}