views:

1010

answers:

2

I'd like to know how one would create an application that starts in the background. Im 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 shellscript for my application or can i do this from C?

+1  A: 

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

opyate
I'd like to get it programmatically. From within the C-program. Or do you suggest that i create a shell-script?
Filip Ekberg
JesperE's answer is spot-on if you want to do it programmatically.
opyate
+5  A: 
  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.
JesperE