No more zombies.

This commit is contained in:
number Zero 2016-02-21 01:15:38 +03:00
parent 81e488e287
commit 8a8aab4f9b
2 changed files with 13 additions and 9 deletions

8
func.S
View File

@ -17,7 +17,7 @@
errstr: .ascii "error happened\n"
.set errstr_len, .-errstr
.set buffer_size, 1024
.set buffer_size, 1024*1024
buffer: .skip buffer_size, 0
.text
@ -105,9 +105,7 @@ error:
movq $errstr, %rsi
movq $errstr_len, %rdx
syscall
exit:
movq $__NR_exit, %rax
movq $0, %rdi
movq $0, %rsi
movq $2, %rdi
syscall
movq $0, 0

14
main.S
View File

@ -8,7 +8,8 @@
#define PF_INET 2
#define AF_INET PF_INET
#define SOCK_STREAM 1
#define SOCK_STREAM 1
#define CLONE_PARENT 0x00008000
#define PORT 20335
@ -100,8 +101,13 @@ loop:
movq $message_len, %rdx
call write_buf
movq $__NR_fork, %rax
syscall /* fork! */
movq $__NR_clone, %rax
movq $CLONE_PARENT, %rdi
movq $0, %rsi
movq $0, %rdx
movq $0, %r10
movq $0, %r8
syscall /* fork! (through clone()) */
cmp $-1, %rax
jz error
test %rax, %rax
@ -135,7 +141,7 @@ error:
syscall
movq $__NR_exit, %rax
movq $0, %rdi
movq $1, %rdi
syscall
/* this line is unreachable */