1. 编写一个HelloWorld程序
#include <stdio.h>
#include <stdlib.h>
 
int main(int argc,char **argv)
{
  while(1)
  {
    printf("hello world\n");
    sleep(2);//2s
  }
}

  1. gcc编译生成可执行程序:hello
gcc -o hello hello.c
  1. 在/usr/lib/systemd/system目录下创建文件:hello.service,内容如下:
[Unit]
Description=hello service !

[Service]
ExecStart=/home/yan/projects/hello

[Install]
WantedBy=multi-user.target

  1. 运行服务
service hello start
service hello status
service hello stop

相关文章:

  • 2021-12-13
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-18
  • 2021-08-03
  • 2022-01-29
  • 2021-06-03
猜你喜欢
  • 2022-12-23
  • 2021-09-07
  • 2022-12-23
  • 2021-09-13
  • 2021-04-30
  • 2022-12-23
相关资源
相似解决方案