linux使用xinetd自定義服務

系統:ubuntu 12.04


1.安裝xinetd 

#apt-get install xinetd


2.編寫自己的一個程序

#vim /workspace/hello.c

###################################

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
void main(void){
      printf("Welcom!\nHello! World!\n");
}

###################################


#gcc -o hello hello.c    //編譯生成hello可執行文件


3.修改/etc/xinetd.conf

添加如下內容

service demobin
{
socket_type = stream
protocol    = tcp
wait        = no
user        = root
server      = /home/junxianchen/workspace/test/hello
}

4.修改/etc/service

添加如下內容

demobin      20001/tcp


5.重啓xinetd服務

#/etc/init.d/xinetd restart


6測試

#telnet localhost demobin

Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Welcom!
Hello! World!
Connection closed by foreign host.


測試成功

發佈了39 篇原創文章 · 獲贊 30 · 訪問量 11萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章