summaryrefslogtreecommitdiffstats
path: root/03_exercise/cli/client.c
diff options
context:
space:
mode:
Diffstat (limited to '03_exercise/cli/client.c')
-rw-r--r--03_exercise/cli/client.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/03_exercise/cli/client.c b/03_exercise/cli/client.c
index e5f2f84..ea4eda9 100644
--- a/03_exercise/cli/client.c
+++ b/03_exercise/cli/client.c
@@ -16,6 +16,7 @@
#define BUF_SIZE 2048
int sock;
+pid_t pid;
/* Signal Handler for SIGINT */
void sigintHandler(int sig_num) {
@@ -26,6 +27,7 @@ void sigintHandler(int sig_num) {
}
printf("Terminating client\n");
fflush(stdout);
+ kill(pid, SIGKILL);
exit(-1);
}
@@ -147,10 +149,10 @@ int main() {
signal(SIGINT, &sigintHandler);
- pid_t pid = fork();
+ pid = fork();
int done = 0;
- if (pid == 0) {
+ if (pid != 0) {
read_stdin(&done);
} else {
read_server_sock(&done);
@@ -174,6 +176,7 @@ void read_server_sock(int *done) {
}
}
}
+ kill(pid, SIGKILL);
}
@@ -186,7 +189,6 @@ void read_stdin(int *done) {
if ((length = read(STDIN_FILENO, stdinp_buffer, BUF_SIZE)) > 0) {
switch (parse(sock, stdinp_buffer, length)) {
case CONTINUE:
- printf("$> ");
continue;
case BREAK:
*done = 1;
@@ -196,4 +198,5 @@ void read_stdin(int *done) {
}
}
}
+ kill(pid, SIGKILL);
}