Created
October 14, 2009 09:46
-
-
Save miyucy/209924 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <limits.h> | |
#include <unistd.h> | |
void write_pid_file(const char* pid_file) | |
{ | |
// getcwd | |
FILE* fp = fopen(pid_file, "w"); | |
if(fp) | |
{ | |
fprintf(fp, "file(%d):%d\n", __LINE__, (int)getpid()); | |
fclose(fp); | |
} | |
} | |
int main(int argc, char *argv[]) | |
{ | |
char pid_file[PATH_MAX]; | |
strncat(getcwd(pid_file, PATH_MAX), "/pid", strlen("/pid")); | |
fprintf(stdout, "stdout(%d):%d\n", __LINE__, (int)getpid()); | |
fprintf(stderr, "stderr(%d):%d\n", __LINE__, (int)getpid()); | |
daemon(0, 0); | |
fprintf(stdout, "stdout(%d):%d\n", __LINE__, (int)getpid()); | |
fprintf(stderr, "stderr(%d):%d\n", __LINE__, (int)getpid()); | |
write_pid_file(pid_file); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment