-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3b.c
More file actions
43 lines (34 loc) · 905 Bytes
/
3b.c
File metadata and controls
43 lines (34 loc) · 905 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <syslog.h>
#include <string.h>
int main(void) {
FILE* fd;
pid_t pid, sid;
pid = fork();
if (pid < 0)
exit(EXIT_FAILURE);
if (pid > 0)
exit(EXIT_SUCCESS);
umask(0);
sid = setsid();
if (sid < 0)
exit(EXIT_FAILURE);
if ((chdir("/")) < 0)
exit(EXIT_FAILURE);
close(STDIN_FILENO);
close(STDOUT_FILENO);
close(STDERR_FILENO);
fd=fopen("/home/hello/myfile.txt","w+");
while (1) {
fprintf(fd,"Running");
fflush(fd);
sleep(5);
}
exit(EXIT_SUCCESS);
}