For Programmers: Free Programming Magazines  


Home > Archive > Unix Programming > September 2005 > ctrl + c









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author ctrl + c
rishi.shah@patni.com

2005-09-29, 9:57 pm

I am developing a project in unix/c++ in which
I have the server process that has invoked several client processes on
different machines. To terminate the server process the user will press
ctrl + c.
Now when ctrl + c is pressed, I want to signal the client processes to
terminate as well.
Now here I have the doubts.
When I press ctrl+c does the server process get a chance to process
further instructions or is it killed immediately?
Is there is some way in which I can delay the killing process so that I
can signal the clients to terminate?
The client and server have TCP connection established so I am planning
to send the signal on the TCP connection.
I cannot kill the client processes since I have not forked the
processes but invoked them using exec client(.exe) on a separate
machine.

Gordon Burditt

2005-09-29, 9:57 pm

>I am developing a project in unix/c++ in which
>I have the server process that has invoked several client processes on
>different machines. To terminate the server process the user will press
>ctrl + c.


That generates SIGINT on a lot of configurations.

>Now when ctrl + c is pressed, I want to signal the client processes to
>terminate as well.
>Now here I have the doubts.
>When I press ctrl+c does the server process get a chance to process
>further instructions or is it killed immediately?


If you catch SIGINT, the server has a chance to clean up.

>Is there is some way in which I can delay the killing process so that I
>can signal the clients to terminate?


Call signal() to set up a signal handling routine for SIGINT. In
that routine, call kill() as needed to signal the clients. Then
exit. Oh, wait, you didn't mean that kind of signal.

>The client and server have TCP connection established so I am planning
>to send the signal on the TCP connection.


HOW do you send the signal? If you design the protocol so that
CLOSING the TCP connection is an indicator to shut down, then you
don't have to catch SIGINT, it will happen when the process dies
anyway. Otherwise, send a shutdown message from the signal handler
out on the sockets.

>I cannot kill the client processes since I have not forked the
>processes but invoked them using exec client(.exe) on a separate
>machine.


Gordon L. Burditt
joe@invalid.address

2005-09-30, 6:59 pm

"rishi.shah@patni.com" <rishi.shah@patni.com> writes:

> I am developing a project in unix/c++ in which I have the server
> process that has invoked several client processes on different
> machines. To terminate the server process the user will press ctrl +
> c. Now when ctrl + c is pressed, I want to signal the client
> processes to terminate as well.


If the clients are listening to the connection they will see it's been
closed when the server exits. You can define that as telling them to
exit as well.

> Now here I have the doubts. When I press ctrl+c does the server
> process get a chance to process further instructions or is it killed
> immediately?


If you catch it, no.

> Is there is some way in which I can delay the killing
> process so that I can signal the clients to terminate? The client
> and server have TCP connection established so I am planning to send
> the signal on the TCP connection. I cannot kill the client
> processes since I have not forked the processes but invoked them
> using exec client(.exe) on a separate machine.


The connection being dropped is probably all the signal you need for
that.

Joe
--
It was impossible to get a conversation going;
everybody was talking too much.
- Yogi Berra
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com