473,396 Members | 1,970 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,396 software developers and data experts.

Generate SIGIO

Hi,

I am tring to use the following code to generate SIGIO, but there is no
signal. Is there anything wrong?

#include <stdio.h>
#include <signal.h>
#include <fcntl.h>

void
handle (int sig)
{
printf ("GET SIGIO\n");
}

int
main (void)
{
fcntl (0, F_SETFL, FASYNC);
fcntl (0, F_SETOWN, getpid ());
signal (SIGIO, handle);
write (0, "ls\n", 3);
return 0;
}

Qian

Sep 3 '06 #1
1 5447
ca*****@gmail.com wrote:
Hi,

I am tring to use the following code to generate SIGIO, but there is no
signal. Is there anything wrong?
There is no SIGIO in Standard C.
#include <stdio.h>
#include <signal.h>
#include <fcntl.h>
Not a Standard header.
void
handle (int sig)
{
printf ("GET SIGIO\n");
Calling printf from a signal handler is undefined behavior in Standard
C.
}

int
main (void)
{
fcntl (0, F_SETFL, FASYNC);
fcntl (0, F_SETOWN, getpid ());
fcntl is not a Standard C function and is off-topic here.
signal (SIGIO, handle);
write (0, "ls\n", 3);
write is not a Standard C function and is off-topic here. In Standard
C you can use the raise() function to send a signal to the executing
process instead of performing an operation in the hopes that it will
send such a signal to your process.
return 0;
}
The signal functionality provided by Standard C is limited almost to
the point of uselessness. Below is a simple Standard C example using
signal and raise:

#include <stdio.h>
#include <signal.h>

volatile sig_atomic_t signal_pending;

void handle (int sig) {
signal_pending = 1;
}

int main (void) {
if (signal(SIGTERM, handle) == SIG_ERR)
puts("failed to install signal handler");
else
puts("successfully installed signal handler");

raise(SIGTERM);
if (signal_pending) {
puts("received signal");
signal_pending = 0;
}
return 0;
}

The signal functionality provided by Standard C is limited, unreliable,
and chock-full of caveats. The POSIX Standard greatly extends the
usefulness of signal handling and adds functionality. Discussion of
the POSIX functions should be done in comp.unix.programmer.

Robert Gamble

Sep 3 '06 #2

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

Similar topics

0
by: Almoni | last post by:
Hi, I have a few .xsd files that include each other in the following way: <!-- lets call the main schema file AA.xsd and it includes BB.xsd inside it --> <xs:schema...
3
by: Garry Dawkins | last post by:
Hey Frank, I'm a novice with this taking over someone elses application. I'm attempting to add a dataset to a page. I have the query to populate the page and I have the walkthrough instructions. ...
1
by: jtsree | last post by:
I am Using (Windows XP) Visual Studio.net 2003 professional edition working on VB.net language. I am bulding a very very simple project in VB.net where i connect to Access Database by dragging...
9
by: Henk Verhoeven | last post by:
We are not alone! "Where other MDA tools are generating programmingcode, Codeless chooses not to generate code at all". OK, phpPeanuts is not an MDA tool (it has no fancy modeling GUI). But it...
4
by: Stephen | last post by:
I need to generate input XML for another application by serialising classes defined in an XSD document. The code below will generate the XML I require but I need to generate this in memory rather...
1
by: c_attitude | last post by:
Is it possible to catch a signal at the parallel port without using file descriptor? I am using the ioperm, inb and outb functions to communicate vi parallel port. In this case how do i catch a...
1
by: A Traveler | last post by:
Hello, i am having this problem. The exact error message is: "Unable to generate code for a value of type 'System.Web.UI.Page'. This error occurred while trying to generate the property value for...
0
by: ward | last post by:
Greetings. Ok, I admit it, I bit off a bit more than I can chew. I need to complete this "Generate Report" page for my employer and I'm a little over my head. I could use some additional...
2
by: bthubbard | last post by:
This may not be the best group in which to post this. If there is a better location please direct me there. I have been experimenting with Sandcastle to generate CHM help file documentation for...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.