7 pthread_t threads
[255];
9 void cleanup_handler(void *pipe
) {
13 cast_pipe
= (FILE *) pipe
;
18 void *exec_newthread(void *input
) {
20 char *cast_input
, *out_buf
;
23 out_buf
= (char *) calloc(1, 512);
24 cast_input
= (char *) input
;
26 out_pipe
= popen(cast_input
, "r");
27 pthread_cleanup_push(cleanup_handler
, (void *) out_pipe
);
28 pthread_setcancelstate(PTHREAD_CANCEL_ENABLE
, NULL
);
32 fgets(out_buf
, 255, out_pipe
);
37 printf("%s", out_buf
);
40 pthread_cleanup_pop(1);
45 int main(int argc
, char *argv
[]) {
51 input_buf
= (char *) calloc(1, 512);
53 while(strncmp(input_buf
, "quit", 4)) {
55 fgets(input_buf
, 255, stdin
);
57 if(!strncmp(input_buf
, "quit", 4))
60 pthread_create(&threads
[thread_counter
], NULL
, exec_newthread
, input_buf
);
61 pthread_detach(threads
[thread_counter
]);