Professional Documents
Culture Documents
Software Project Development Spring Semester
Software Project Development Spring Semester
(Usually)
Run in background
No STDOUT nor STDERR?
(Usually)
I/O Redirection? Only one execution instance
is allowed. How?
while(1) {
fprintf(stdout, “STDOUT: I’m alive\n”);*in_fp, char *buf) {
void redirect(FILE
fprintf(stderr, “STDERR:int
I’mfd
alive\n”);
= fileno(in_fp);
sleep(1); FILE *fp = fopen(buf, “w”);
} if(fp == NULL) { ...... }; // kill yourself
} close(fd);
else { dup2(fileno(fp), fd);
printf(“Created a bg process: %d\n”, pid);
fclose(fp);
exit(0); }
}
ist?
f ex /var/run/apache2.pid
cki
2nd instance che
(1)
p
Ste Ye
s…
Apache
Step (2) Kill himself!
1st instance
Step (1) remove file.
Apache 1234
5678
Step (2) Kill himself!
I wanna quit…
ist?
f ex /var/run/apache2.pid
cki
3rd instance che
(1)
p
Ste No
…
Apache d write
p (2 ) c reate an
St e