Filip Ekberg
Filip Ekberg

Reputation: 36287

Getting the Program Process (Service and Daemon) on Linux in C

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:

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.

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?

Upvotes: 2

Views: 1960

Answers (2)

JesperE
JesperE

Reputation: 64404

  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.

Upvotes: 5

opyate
opyate

Reputation: 5428

On *nix, get the process id with ps or if you know the process name, do

ps aux | grep processname

And to run any program as a daemon, use nohup

Upvotes: 1

Related Questions