blob: 0e8973dd1715cca81c1eb2beb942dcd973567eb1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
int main(int argc, char** argv)
{
// need a command to run
if (argc <= 1) return 1;
// fork to disown the child
pid_t child;
if (child = fork())
{
if (child == -1)
{
perror("fork");
return 1;
}
printf("%ld\n", (long)child);
return 0;
}
// silence output
if (!freopen("/dev/null", "w", stdout)) fprintf(stdout, "Failed to silence stdout\n");
if (!freopen("/dev/null", "w", stderr)) fprintf(stderr, "Failed to silence stderr\n");
// run the command
if (execvp(argv[1], argv + 1))
{
if (freopen("/dev/tty", "w", stderr)) perror(argv[0]);
}
return 1;
}
|