473,405 Members | 2,338 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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

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

Sep 28 '06 #1
3 1801
In article <11**********************@d34g2000cwd.googlegroups .com>,
no*****@yahoo.com <no*****@yahoo.comwrote:
>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.
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
Sep 28 '06 #2
no*****@yahoo.com wrote:
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();
[...]
}

Sep 29 '06 #3

ar****@gmail.com wrote:
no*****@yahoo.com wrote:
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)

Sep 29 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: John Lin | last post by:
Howdy, I want to know how to tell if a forked process is done. Actually, my real question is that I want to run a shell script inside of a python script, and after the shell script has...
1
by: Peter Åstrand | last post by:
There's a new PEP available: PEP 324: popen5 - New POSIX process module A copy is included below. Comments are appreciated. ---- PEP: 324 Title: popen5 - New POSIX process module
2
by: Ishwar Rattan | last post by:
Here is a piece code (according to blurb on os.wait, the lower order 7 bits of exit status of process should contain the signal number of signal that terminated the process..) and signal number...
13
by: Siemel Naran | last post by:
Hi. I posted this question to comp.lang.c++, but am rephrasing it a bit from what I learned and posting to comp.lang.c++.moderated for more insight. So how do I solve my problem? I want it so...
18
by: jas | last post by:
Hi, I would like to start a new process and be able to read/write from/to it. I have tried things like... import subprocess as sp p = sp.Popen("cmd.exe", stdout=sp.PIPE)...
1
by: Alexander N. Spitzer | last post by:
I am trying to write a program that will fork a process, and execute the given task... the catch is that if it runs too long, I want to clean it up. this seemed pretty straight forward with a...
3
by: felixfix | last post by:
Hi all, I am just wondering if something is wrong with my program. What it bascially does is to output a fibonacci sequence base on the command-line output. If I give a 5, it will generate the...
2
by: mumebuhi | last post by:
I am having problem to kill the following script completely. The script basically does the following. The main thread creates a new thread, which does a completely useless thing, and then starts...
8
by: =?ISO-8859-15?B?TnXxbw==?= I.G | last post by:
Hello to everybody: I'm trying to get some information about "process management". Let's explain a little... I want to write some code that allows me to execute some "aplications" and collect...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.