473,606 Members | 2,115 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1819
In article <11************ **********@d34g 2000cwd.googleg roups.com>,
no*****@yahoo.c om <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.progr ammer 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.c om 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_calle d()
{
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.co m wrote:
no*****@yahoo.c om 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_calle d()
{
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
13065
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 finished running, I want to do more stuff *condition* on the fact that the shell script has finished running, inside the same python script. The only way I can think of is to fork a process and then call the
1
2593
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
2302
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 should be 8 (SIGFPE), similar logic in C-code produces expected result. Any pointers? -ishwar ----
13
4843
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 that when the user presses Ctrl-C or eds the task from task manager (or the kill command in UNIX) then the system should shutdown gracefully. This means it should call the destructors of all objects, which means freeing dynamic memory, closing...
18
4871
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) p.stdin.write("hostname\n") however, it doesn't seem to work. I think the cmd.exe is catching it.
1
3456
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 single executable being run from the fork. The problem I am having now is that if I call a shell scripts, then lets say calls "xterm &", after the timeout has occurred, I kill the shell script, but the xterm is still running... I cannot seem to kill...
3
2959
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 first 5 fibonacci number. The problem is, I thought the parent process will always go first, and so here I should get "0, 1, 1, 2, 3" But I ran the program, it will give me "1, 2, 3, 0, 1", which is, the child process ran first. Is there any way...
2
4243
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 excepting for a connection via socket. # start import pickle import signal import simplejson import socket
8
4036
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 the data they produced. This apllicationis a kind of "client" that must work in more that one SO (for example *NIX, Windows98, Win2000). So my question is about what kind of "managemet" of this proccess I can do, and how to start and "monitor"...
0
7942
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8433
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8429
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8084
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
5963
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5461
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3922
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3969
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2443
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.