A first attempt at nohup
This commit is contained in:
parent
ca43240230
commit
90cc2069bd
1 changed files with 27 additions and 0 deletions
27
nohup.c
Normal file
27
nohup.c
Normal file
|
@ -0,0 +1,27 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main(int argc, char ** argv) {
|
||||
char ** util_argv;
|
||||
|
||||
if(signal(SIGHUP, SIG_IGN) == SIG_ERR) {
|
||||
return 127;
|
||||
}
|
||||
|
||||
util_argv = calloc(argc, sizeof(*argv));
|
||||
if(util_argv == NULL) {
|
||||
return 127;
|
||||
}
|
||||
|
||||
for(int i = 0; i < argc - 1; i++) {
|
||||
util_argv[i] = calloc(strlen(argv[i+1]) + 1, sizeof(*(util_argv[i])));
|
||||
strcpy(util_argv[i], argv[i+1]);
|
||||
}
|
||||
util_argv[argc-1] = NULL;
|
||||
|
||||
if(execvp(util_argv[0], util_argv) < 0) {
|
||||
return 126;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue