Skip to content

Commit 5e7522d

Browse files
Listeria monocytogenesFrancesco149
Listeria monocytogenes
authored andcommitted
wait for children
1 parent 8c9fc4c commit 5e7522d

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

httpd.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#define SO_REUSEADDR 2
55
#define SOL_SOCKET 1
66
#define O_RDONLY 0
7+
#define WNOHANG 1
78

89
typedef unsigned short uint16_t;
910
typedef unsigned int uint32_t;
@@ -19,6 +20,8 @@ typedef struct {
1920
char sin_zero[8]; /* 16 */
2021
} sockaddr_in_t;
2122

23+
struct rusage;
24+
2225
ssize_t read(int fd, void *buf, size_t nbyte);
2326
ssize_t write(int fd, const void *buf, size_t nbyte);
2427
int open(const char *path, int flags);
@@ -31,6 +34,7 @@ int listen(int socket, int backlog);
3134
int setsockopt(int socket, int level, int option_name, const void *option_value,
3235
socklen_t option_len);
3336
int fork();
37+
int wait4(int pid, int *wstatus, int options, struct rusage *rusage);
3438
void exit(int status);
3539

3640
static size_t strlen(const char *s) {
@@ -164,6 +168,7 @@ int main(int argc, char *argv[]) {
164168
sock = tcp_listen(&addr, &yes, sizeof(yes));
165169
while (1) {
166170
int pid, clientfd;
171+
while (wait4(-1, 0, WNOHANG, 0) > 0);
167172
if ((clientfd = accept(sock, 0, 0)) < 0) {
168173
perror("accept");
169174
} else if ((pid = fork()) < 0) {

start.S

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
x:; \
1111
add r9,n
1212

13+
c(wait4, 1) /* 61 */
1314
c(exit, 3) /* 60 */
1415
c(fork, 3) /* 57 */
1516
c(setsockopt, 4) /* 54 */

0 commit comments

Comments
 (0)