获取程序进程(服务和守护进程)在Linux上使用C [英] Getting the Program Process (Service and Daemon) on Linux in C

查看:381
本文介绍了获取程序进程(服务和守护进程)在Linux上使用C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道怎么一会创建一个在后台启动的应用程序。目前,我正在创造一个在C网络服务器作为一个小项目,既要学习一些旧的C和Linux Socket编程。但我目前关注的是:


  • 如何获取当前进程号?

我要得到这个,因为当我启动的过程中,我要显示谁启动该服务的用户进程号。


  • 我的第二个问题是,我该如何开始我的应用程序作为一个守护进程在后台运行?

我如何应该这样做的任何引用,教程和/或视频为AP preciated!


也许我是有点不清;我想从C左右的时间内获取进程ID,我需要我的应用程序创建一个shell脚本或者我可以做到这一点从C?


解决方案

  1. 要获得正在运行的进程标识,使用 GETPID()功能。

  2. 要创建一个后台程序,即在后台运行分离的进程,按照这些说明

I'd like to know how one would create an application that starts in the background. I'm currently creating a webserver in C as a little project, both to learn some old C and Linux Socket Programming. But my current concern is:

  • How do I get the current process number?

I want to get this because when I start the process, I want to display the process number for the user who starts the service.

  • My second problem is, how do I start my application as a Daemon to run in the background?

Any references, tutorials and/or videos on how I'd do this is appreciated!


Maybe I was a little bit unclear; I want to get the Process ID from within C. So, do I need to create a shell script for my application or can I do this from C?

解决方案

  1. To get the running process' identifier, use the getpid() function.
  2. To create a daemon, i.e. a detached process running in the background, follow these instructions.

这篇关于获取程序进程(服务和守护进程)在Linux上使用C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆