setsid.c
来自「Util-linux 软件包包含许多工具。其中比较重要的是加载、卸载、格式化、分」· C语言 代码 · 共 49 行
C
49 行
/* * setsid.c -- execute a command in a new session * Rick Sladkey <jrs@world.std.com> * In the public domain. * * 1999-02-22 Arkadiusz Mi秌iewicz <misiek@pld.ORG.PL> * - added Native Language Support * * 2001-01-18 John Fremlin <vii@penguinpowered.com> * - fork in case we are process group leader * */#include <stdio.h>#include <unistd.h>#include <stdlib.h>#include "nls.h"intmain(int argc, char *argv[]) { setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); if (argc < 2) { fprintf(stderr, _("usage: %s program [arg ...]\n"), argv[0]); exit(1); } if (getpgrp() == getpid()) { switch(fork()){ case -1: perror("fork"); exit(1); case 0: /* child */ break; default: /* parent */ exit(0); } } if (setsid() < 0) { perror("setsid"); /* cannot happen */ exit(1); } execvp(argv[1], argv + 1); perror("execvp"); exit(1);}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?