Connecting Tech Pros Worldwide Forums | Help | Site Map

How to let the process exit if the signal its waiting for doesn't arrive

norm4h8@yahoo.com
Guest
 
Posts: n/a
#1: Sep 28 '06
Hi!

I have a question about how to create a process in such a way that it
would terminate itself if its wated for input for too long.

Here is the story. I have 2 different files, say R.c and S.c, which
have a named pipe between them and send each other signals. R process
starts first, it opens a named pipe and waits for S to connect. S
connects to the pipe, writes something to it and sends the signal to R
indicating that R can read. When R receives a signal from S, it reads
the data, sends the signal back to S that the data was read, and
suspends waiting for another signal from S to read again, and so on.

My question is when R just starts and waits for S to connect, in case S
doesn't connect, so that R would wait indefinitely, is there a way to
set a clock or something in R to terminate after some time, without
affecting the rest of the execution in case S does connect.

Sorry if my explanation is a little all over the place...
I'd really appreciate any help or any ideas.

Thanks a lot
norm4h8


Walter Roberson
Guest
 
Posts: n/a
#2: Sep 28 '06

re: How to let the process exit if the signal its waiting for doesn't arrive


In article <1159459691.860092.237710@d34g2000cwd.googlegroups .com>,
norm4h8@yahoo.com <norm4h8@yahoo.comwrote:
Quote:
>I have a question about how to create a process in such a way that it
>would terminate itself if its wated for input for too long.
You can't do that using only standard C. Standard C has no library
calls with timeouts, and no library calls that implement alarms.
(Standard C doesn't even require that there be a useful clock
on the system!)

You will need to use an implementation-dependant extension.
Quote:
Here is the story. I have 2 different files, say R.c and S.c, which
have a named pipe between them and send each other signals.
"named pipes" are beyond the knowledge of C; they are implementation
extensions. The fact that your system has named pipes suggests
strongly that you are using a Unix-like system; in that case,
comp.unix.programmer can probably lead you to an appropriate solution,
if you tell them which platform + OS version you are using.

[off topic]
Many systems implement an OS extension named alarm() .
--
"No one has the right to destroy another person's belief by
demanding empirical evidence." -- Ann Landers
arajak@gmail.com
Guest
 
Posts: n/a
#3: Sep 29 '06

re: How to let the process exit if the signal its waiting for doesn't arrive


norm4h8@yahoo.com wrote:
Quote:
Hi!
>
I have a question about how to create a process in such a way that it
would terminate itself if its wated for input for too long.
>
Here is the story. I have 2 different files, say R.c and S.c, which
have a named pipe between them and send each other signals. R process
starts first, it opens a named pipe and waits for S to connect. S
connects to the pipe, writes something to it and sends the signal to R
indicating that R can read. When R receives a signal from S, it reads
the data, sends the signal back to S that the data was read, and
suspends waiting for another signal from S to read again, and so on.
>
My question is when R just starts and waits for S to connect, in case S
doesn't connect, so that R would wait indefinitely, is there a way to
set a clock or something in R to terminate after some time, without
affecting the rest of the execution in case S does connect.
>
Sorry if my explanation is a little all over the place...
I'd really appreciate any help or any ideas.
>
Thanks a lot
norm4h8
U can define somelines in ur S.c which actually waits for a signal from
R.c :
==S.c==
//handler for SIGALRM
void handler_sigalrm(int signo)
{
[...]
printf("\nNo signal from R.c--hence exiting--TIMEOUT");
[...]
}

int urfunc_in_which_pause_is_called()
{
signal(SIGALRM,handler_sigalrm);
[...]
// raise an alarm for N seconds -- if u need N seconds timeout
+ alarm(N) ;
pause();
[...]
}

arajak@gmail.com
Guest
 
Posts: n/a
#4: Sep 29 '06

re: How to let the process exit if the signal its waiting for doesn't arrive



arajak@gmail.com wrote:
Quote:
norm4h8@yahoo.com wrote:
>
Quote:
Hi!

I have a question about how to create a process in such a way that it
would terminate itself if its wated for input for too long.

Here is the story. I have 2 different files, say R.c and S.c, which
have a named pipe between them and send each other signals. R process
starts first, it opens a named pipe and waits for S to connect. S
connects to the pipe, writes something to it and sends the signal to R
indicating that R can read. When R receives a signal from S, it reads
the data, sends the signal back to S that the data was read, and
suspends waiting for another signal from S to read again, and so on.

My question is when R just starts and waits for S to connect, in case S
doesn't connect, so that R would wait indefinitely, is there a way to
set a clock or something in R to terminate after some time, without
affecting the rest of the execution in case S does connect.

Sorry if my explanation is a little all over the place...
I'd really appreciate any help or any ideas.

Thanks a lot
norm4h8
>
U can define somelines in ur S.c which actually waits for a signal from
R.c :
==S.c==
//handler for SIGALRM
void handler_sigalrm(int signo)
{
[...]
printf("\nNo signal from R.c--hence exiting--TIMEOUT");
[...]
}
>
int urfunc_in_which_pause_is_called()
{
signal(SIGALRM,handler_sigalrm);
[...]
// raise an alarm for N seconds -- if u need N seconds timeout
+ alarm(N) ;
pause();
[...]
}
Solution is completely based on implementation on UNIX(assumed as u are
using something called named pipes)

Closed Thread