- 浏览: 223298 次
- 性别:
- 来自: 北京
最新评论
-
qq452739204:
如果构造的报文大于mtu值,是否需要分片之后再发送出去列?
Linux内核构造数据包并发送(二)(dev_queue_xmit方式) -
xingzengmou:
你好,我搞的原理跟你差不多,但播放的时候有papapa的声音, ...
AudioRecord和AudioTrack类的使用 -
wenjiefeng:
楼主,你有录制pcm格式和播放pcm格式的录音器的demo吗, ...
AudioRecord和AudioTrack类的使用 -
lovepeakingA:
...
AudioRecord和AudioTrack类的使用 -
ZaneLee007:
假的,不学无术
Android禁用键盘的所有按键
This is a template for a Linux daemon written in C. It includes:
- Command-line argument handling via getopt
- Signal Handling
- Syslog output and filtering via setlogmask
- Forking of process
- Changing of file mode mask
- Setting of Session ID
- Closing of STDOUT, STDIN, and STDERR
The following code can be compiled using the following command (assuming gcc):
gcc -DDEBUG -o daemonname downloaded_file.c
The code:
/* * Example daemon shell code for all of the requirements of a basic * linux daemon written in C. * * To use this code, search for 'TODO' and follow the directions. * * To compile this file: * gcc -o [daemonname] thisfile.c * * Substitute gcc with cc on some platforms. * * Peter Lombardo (peter AT lombardo DOT info) * 5/1/2006 * */ #include <sys /types.h> #include </sys><sys /stat.h> #include <stdio .h> #include <stdlib .h> #include <fcntl .h> #include <errno .h> #include <unistd .h> #include <syslog .h> #include <string .h> #include <assert .h> #include <signal .h> // TODO: Change '[daemonname]' to the name of _your_ daemon #define DAEMON_NAME "[daemonname]" #define PID_FILE "/var/run/[daemonname].pid" /************************************************************************** Function: Print Usage Description: Output the command-line options for this daemon. Params: @argc - Standard argument count @argv - Standard argument array Returns: returns void always **************************************************************************/ void PrintUsage(int argc, char *argv[]) { if (argc >=1) { printf("Usage: %s -h -nn", argv[0]); printf(" Options:n"); printf(" -ntDon't fork off as a daemon.n"); printf(" -htShow this help screen.n"); printf("n"); } } /************************************************************************** Function: signal_handler Description: This function handles select signals that the daemon may receive. This gives the daemon a chance to properly shut down in emergency situations. This function is installed as a signal handler in the 'main()' function. Params: @sig - The signal received Returns: returns void always **************************************************************************/ void signal_handler(int sig) { switch(sig) { case SIGHUP: syslog(LOG_WARNING, "Received SIGHUP signal."); break; case SIGTERM: syslog(LOG_WARNING, "Received SIGTERM signal."); break; default: syslog(LOG_WARNING, "Unhandled signal (%d) %s", strsignal(sig)); break; } } /************************************************************************** Function: main Description: The c standard 'main' entry point function. Params: @argc - count of command line arguments given on command line @argv - array of arguments given on command line Returns: returns integer which is passed back to the parent process **************************************************************************/ int main(int argc, char *argv[]) { #if defined(DEBUG) int daemonize = 0; #else int daemonize = 1; #endif // Setup signal handling before we start signal(SIGHUP, signal_handler); signal(SIGTERM, signal_handler); signal(SIGINT, signal_handler); signal(SIGQUIT, signal_handler); int c; while( (c = getopt(argc, argv, "nh|help")) != -1) { switch(c){ case 'h': PrintUsage(argc, argv); exit(0); break; case 'n': daemonize = 0; break; default: PrintUsage(argc, argv); exit(0); break; } } syslog(LOG_INFO, "%s daemon starting up", DAEMON_NAME); // Setup syslog logging - see SETLOGMASK(3) #if defined(DEBUG) setlogmask(LOG_UPTO(LOG_DEBUG)); openlog(DAEMON_NAME, LOG_CONS | LOG_NDELAY | LOG_PERROR | LOG_PID, LOG_USER); #else setlogmask(LOG_UPTO(LOG_INFO)); openlog(DAEMON_NAME, LOG_CONS, LOG_USER); #endif /* Our process ID and Session ID */ pid_t pid, sid; if (daemonize) { syslog(LOG_INFO, "starting the daemonizing process"); /* Fork off the parent process */ pid = fork(); if (pid < 0) { exit(EXIT_FAILURE); } /* If we got a good PID, then we can exit the parent process. */ if (pid > 0) { exit(EXIT_SUCCESS); } /* Change the file mode mask */ umask(0); /* Create a new SID for the child process */ sid = setsid(); if (sid < 0) { /* Log the failure */ exit(EXIT_FAILURE); } /* Change the current working directory */ if ((chdir("/")) < 0) { /* Log the failure */ exit(EXIT_FAILURE); } /* Close out the standard file descriptors */ close(STDIN_FILENO); close(STDOUT_FILENO); close(STDERR_FILENO); } //**************************************************** // TODO: Insert core of your daemon processing here //**************************************************** syslog(LOG_INFO, "%s daemon exiting", DAEMON_NAME); //**************************************************** // TODO: Free any allocated resources before exiting //**************************************************** exit(0); }
发表评论
-
ARP头
2010-12-01 17:20 1185ifndef _NET_IF_ARP_H_ #d ... -
自己用libpcap来抓包
2010-12-01 16:40 6921#define APP_NAME &quo ... -
MAC文本格式地址to网络字节序
2010-12-01 16:38 2096#include <sys/types.h& ... -
C语言实现修改IE浏览器的代理设置
2010-11-24 17:18 4574写了一个用C语言实现修 ... -
[转]通过例子学习Lua
2010-11-17 21:25 4663据说本文作者是OGDEV的HACK达人 通过例子学习 ... -
size_t和ssize_t类型
2010-10-22 10:11 1696size_t 是为了方便系统之间的移植而定义的在32位系统 ... -
高速网络环境下基于零拷贝的报文捕获机制
2010-10-19 09:07 4697参看: http://www.linuxjo ... -
sendfile() -- 通过 socket 拷贝文件
2010-10-19 08:53 2654原型: #include <sys/sendfi ... -
零拷贝与 sendfile
2010-10-19 08:47 3671最近在搞zerocopy的东西,看到了这篇文章,拷过来备用! ... -
C++队列实现和队列简介
2010-10-09 11:04 2807队列简介: 队列(Queue)是一种数据结构,可以在队 ... -
定长队列写入文件并读取
2010-10-09 10:57 1345#include "stdio.h" ... -
循环队列
2010-10-09 10:55 1642相信绝大多数都学习过《数据结构》这门课程,而对这门课程里 ... -
自动、静态、 寄存器、易失变量的区别
2010-09-30 08:08 1558自动变量 什么是 ... -
stdarg.h
2010-09-27 09:12 1779stdarg.h是C语言中C标 ... -
extern用法详解
2010-09-27 08:33 13481 基本解释 extern ... -
给线程变量pthread_t *thread动态分配空间
2010-09-26 08:36 3087线程的创建是用下面的几个函数来实现的. #inc ... -
typedef 的用法
2010-09-25 20:43 895用途一: 定义一种类型的别名,而不只是简单 ... -
编写守护进程
2010-09-17 10:43 864#include <stdio.h> #incl ... -
抓包程序的包存储队列
2010-09-17 09:08 776typedef struct _Node { in ... -
浅谈C中的malloc和free
2010-09-03 19:37 872在C语言的学习中,对内存管理这部分的知识掌握尤其重要!之前对C ...
相关推荐
根据《linux/UNIX系统编程手册》的daemon章节写的一个测试become_daemon()函数程序。代码内容99%以上都是书上给的源码。...修改了 makefile文件,makefile.inc 文件未使用;修改了 ***.h> 的路径。
在Linux中专门提供了一个函数来完成这个daemon化的过程,这个函数的原型如下 int daemon (int __nochdir, int __noclose); 如果__nochdir的值为0,则将切换工作目录为根目录;如果__noclose为0,则将标准输入...
The Linux® Networking Architecture: Design and Implementation of Network Protocols in the Linux Kernel By Klaus Wehrle, Frank Pählke, Hartmut Ritter, Daniel Müller, Marc Bechler Publisher :...
这时我们并没有真正的安装上了VMWARE TOOLS软件包,如果您点击菜单:DEVICES,您就会发现光驱的菜单文字变为:ide1:0-> C:\Program Files\VMware\VMware Workstation\Programs\linux.iso,这表示VMWARE将LINUX的ISO...
3a*8*daemon init 幸*启动配置文件当中的需要守护的程序 执行成功返回1,中途出错,返回-1 长界零家墨军零家零率家三哮零座零率零零容岸军零罕型率零零零零牢察座察零零零零季球军零容零 int moniter_ run(struct proc...
rm /home/wwt/linux_r16/lichee/out/sun8iw5p1/linux/common/buildroot/build/buildroot-config/zconf.tab.c make[1]:正在离开目录 `/home/wwt/linux_r16/lichee/buildroot/package/config' # # configuration ...
rm /home/wwt/linux_r16/lichee/out/sun8iw5p1/linux/common/buildroot/build/buildroot-config/zconf.tab.c make[1]:正在离开目录 `/home/wwt/linux_r16/lichee/buildroot/package/config' # # configuration ...
[PM2] Spawning PM2 daemon with pm2_home=/root/.pm2 查看pm2日志,里面报错 root@iZm5e3iekfi2krh6udbikaZ:~/.pm2# vim pm2.log 报错内容 SyntaxError: Unexpected token ... at createScript (vm.js:74:10) ...
2. configure: error: no acceptable C compiler found in $PATH 原因:未安装gcc编译器. 在命令行里敲入gcc –v, 如果提示command not found 就表示你的系统里没有安装gcc编译器 解决办法:yum install gcc ...
不过目前大多数较新的Linux发行版本(包括红旗 Linux、中软Linux、Mandrake Linux等)都可以自动挂装文件系统,但Red Hat Linux除外。 umount 1.作用 umount命令的作用是卸载一个文件系统,它的使用权限是超级...
在Linux系统下配置service启动和关闭 1, 通过命令cd /etc/init.d文件夹下 2, 再通过命令 vim tomcat 进入vim编辑界面 3,用过 i键 现在把下面代码贴入编辑界面 shell脚本如下 #!/bin/bash # This is the ...
/* This is the structure as used in the I2C_RDWR ioctl call */ struct i2c_rdwr_ioctl_data { struct i2c_msg __user *msgs; /* pointers to i2c_msgs */ __u32 nmsgs; /* number of i2c_msgs */ }; ...
# 前言:为什么要使用非root用户运行tomcat root用户启动tomcat有一个严重的问题,那就是tomcat具有root权限。 ... 所以最好不要使用root启动tomcat。 # 正文:非root用户运行tomcat ## tomcat安装 ...
介绍 rsync命令是一个远程数据同步工具,可通过LAN/WAN快速同步多台主机间的文件。rsync使用所谓的“rsync算法”来使...#This is the rsync daemon configuration #global settings pid file = /var/run/rsyncd.pi
Master 12C communications using Raspbian Linux in C++. Perform ADC and DAC experiments. Debounce buttons and switches using hardware and software solutions. Read rotary encoders for direction and ...
前言 Cut 输入字符中指定的...daemon,x,1,1,daemon,/usr/sbin,/usr/sbin/nologin bin,x,2,2,bin,/bin,/usr/sbin/nologin sys,x,3,3,sys,/dev,/usr/sbin/nologin 实战演练 输出每一行的第二个字节内容 > root@wing:~
Hence, it becomes possible for the attacker to issue a command to all the nodes, that target a single node (for example, all nodes in the botnet might be commanded by the attacker to send a TCP SYN ...
20.3.8 小白学习日记三:/etc/passed和/etc/shadow文件内容解析 认识/etc/passwd和/etc/shadow 两个文件是Linux系统中最重要的文件,与用户和用户组有关的信息都在这些... daemon: x:2:2:daemon:/sbin:/sbin/nologin
rootroot@rootroot-E400:~/wyb/ap6212a0_a33_sc3817r/lichee/linux-3.4$ make ARCH=arm menuconfig [*] Networking support ---> <*> Bluetooth subsystem support ---> Bluetooth device drivers ---> < > ...
Docker 开启远程链接(2375端口)提供外部访问1....软件声明 ...vim /usr/lib/systemd/system/docker.service 执行命令后在如下内容,修改红线部分内容,添加 -H tcp://0.0.0.0:2375...systemctl daemon-reload // 1,加载do