⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 p8.1.c

📁 linux程序设计例程
💻 C
字号:
#include <stdio.h>#include <unistd.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>/* Daemonize myself. */intdaemon (int nochdir, int noclose){  pid_t pid;  pid = fork ();  /* In case of fork is error. */  if (pid < 0)    {      perror ("fork");      return -1;    }  /* In case of this is parent process. */  if (pid != 0)    exit (0);  /* Become session leader and get pid. */  pid = setsid();  if (pid < -1)    {      perror ("setsid");      return -1;    }  /* Change directory to root. */  if (! nochdir)    chdir ("/");  /* File descriptor close. */  if (! noclose)    {      int fd;      fd = open ("/dev/null", O_RDWR, 0);      if (fd != -1)	{	  dup2 (fd, STDIN_FILENO);	  dup2 (fd, STDOUT_FILENO);	  dup2 (fd, STDERR_FILENO);	  if (fd > 2)	    close (fd);	}    }  umask (0027);  return 0;}int main(void){	daemon(0,0);	sleep(1000);		return 0;}	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -