Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C, kill all processes

Tags:

c

I have a project for school and I need some help. I'm working in C and I have a server and a client. In server I make a new process for each client with fork. My question is: if I close the server with CTRL+C, how do I kill all the remaining processes ? Thanks


1 Answers

You can store their pids after they are created and then, when quitting, signal sigterm or sigkill to them.

You can do it through shell - killall is what you are searching for under linux.

You could use threads instead of processes (could you? what do the project details say?) and communicate through variables.

like image 173
Dariusz Avatar answered Aug 17 '26 03:08

Dariusz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!