Sponsored Content
Full Discussion: catching interrupts
Top Forums UNIX for Dummies Questions & Answers catching interrupts Post 83772 by Corona688 on Monday 19th of September 2005 03:17:05 PM
Old 09-19-2005
You're not supposed to ask for solutions to be sent by email; when someone searches for this here, they'll only find it if someone posts it.

Ctrl-D isn't a signal, it causes stdin to report EOF. Like so:
Code:
#include <unistd.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
  char buf[512];
  while(!feof(stdin))
    fgets(buf,512,stdin);

  fprintf(stderr,"Ctrl-D or EOF\n");

  return(0);
}

 

9 More Discussions You Might Find Interesting

1. Filesystems, Disks and Memory

Does unix use interrupts?

I'm a freshman here and I have a simple question. Does unix use interrupts which is like Dos? Are they the same? Thx.:cool: (6 Replies)
Discussion started by: Frank_M
6 Replies

2. UNIX for Advanced & Expert Users

Interrupts problems

Hi, My machine is a Unixware 7.1.3 is a files server, and I had never problem with that machine, but since two days, the machine presents slows problems, i think that the problem is te device interrupts, I had checked all and I dont found it any problem. Any idea? Thanks, (sorry my... (2 Replies)
Discussion started by: By_Jam
2 Replies

3. UNIX for Dummies Questions & Answers

Traps and Interrupts

Well, I don't know where exactly to ask this doubt so I'm asking in the newbie section. I was reading about traps and interrupts when I thought of traps as something that cease the control of the OS from the user and interrupts that cease the control yet provide support for multitasking. Am I right... (3 Replies)
Discussion started by: Legend986
3 Replies

4. UNIX for Dummies Questions & Answers

about concept of Interrupts.

Hi all, I am new here ,i want to know about interrupts in detail.What r Interrupts .how they r handeled. Thanx in adavnce. (1 Reply)
Discussion started by: vishwasrao
1 Replies

5. Programming

SIGCHLD interrupts its own handler

Hi. I have a program whose job it is to manage 15 child processes. Sometimes these children die (sometimes deliberately other times with a SEGV). This causes a SIGCHLD to be sent to my program which uses waitpid() in the signal handler to gather information and, in most cases, restart the child.... (3 Replies)
Discussion started by: jrichemont
3 Replies

6. Programming

Getting notified in user-space on interrupts

Hi, I'm working on an AMD opteron running Linux 2.6.28.6 I want to preload a module specific register (MSR) with a value to have it overflow after a number of a specific event counts. As I understand, when the counter in the register overflows, an interrupt will be generated and handled by the... (2 Replies)
Discussion started by: mylinuxforums
2 Replies

7. Linux

Convert ssRawInterrupts into Interrupts Per Sec

am doing performance monitoring to our server through snmp. i need to convert the interrupts raw value (ssRawInterrupts) in UCD-SNMP-MIB to per sec (Interrupts/Sec). What is the exact formula to find the above one. Guide me please. Thanks in advance. (1 Reply)
Discussion started by: maruthu
1 Replies

8. Infrastructure Monitoring

CPU - Interrupts distribution

Hi Gurus, I have a situation runing my ETL tools on the below server. The throughput while processing data is coming very low. When i tried to analyse the CPU stats i got colleceted the mpstat. Server Physical Host Name *********com IP**.***.** OS Type Linux OS Classlinux red hat... (3 Replies)
Discussion started by: r_t_1601
3 Replies

9. UNIX for Dummies Questions & Answers

Do UNIX signals produce interrupts?

Hi folks! I have been reading Vahalia's Unix Internals book, which states the following in the chapter dedicated to signals: Given that, my understanding is that processes running in user mode don't become aware of signals until they switch to kernel mode, where the issig() function is called... (3 Replies)
Discussion started by: Tru69
3 Replies
FGETS(3)						   BSD Library Functions Manual 						  FGETS(3)

NAME
fgets, gets -- get a line from a stream LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <stdio.h> char * fgets(char * restrict str, int size, FILE * restrict stream); char * gets(char *str); DESCRIPTION
The fgets() function reads at most one less than the number of characters specified by size from the given stream and stores them in the string str. Reading stops when a newline character is found, at end-of-file or error. The newline, if any, is retained, and a '' charac- ter is appended to end the string. The gets() function is equivalent to fgets() with an infinite size and a stream of stdin, except that the newline character (if any) is not stored in the string. It is the caller's responsibility to ensure that the input line, if any, is sufficiently short to fit in the string. RETURN VALUES
Upon successful completion, fgets() and gets() return a pointer to the string. If end-of-file or an error occurs before any characters are read, they return NULL. The fgets() and gets() functions do not distinguish between end-of-file and error, and callers must use feof(3) and ferror(3) to determine which occurred. ERRORS
[EBADF] The given stream is not a readable stream. The function fgets() may also fail and set errno for any of the errors specified for the routines fflush(3), fstat(2), read(2), or malloc(3). The function gets() may also fail and set errno for any of the errors specified for the routine getchar(3). SEE ALSO
feof(3), ferror(3), fgetln(3) STANDARDS
The functions fgets() and gets() conform to ANSI X3.159-1989 (``ANSI C89'') and IEEE Std 1003.1-2001 (``POSIX.1''). The IEEE Std 1003.1-2008 (``POSIX.1'') revision marked gets() as obsolescent. CAVEATS
The following bit of code illustrates a case where the programmer assumes a string is too long if it does not contain a newline: char buf[1024], *p; while (fgets(buf, sizeof(buf), fp) != NULL) { if ((p = strchr(buf, ' ')) == NULL) { fprintf(stderr, "input line too long. "); exit(1); } *p = ''; printf("%s ", buf); } While the error would be true if a line longer than 1023 characters were read, it would be false in two other cases: 1. If the last line in a file does not contain a newline, the string returned by fgets() will not contain a newline either. Thus strchr() will return NULL and the program will terminate, even if the line was valid. 2. All C string functions, including strchr(), correctly assume the end of the string is represented by a null ('') character. If the first character of a line returned by fgets() were null, strchr() would immediately return without considering the rest of the returned text which may indeed include a newline. Consider using fgetln(3) instead when dealing with untrusted input. SECURITY CONSIDERATIONS
Since it is usually impossible to ensure that the next input line is less than some arbitrary length, and because overflowing the input buf- fer is almost invariably a security violation, programs should NEVER use gets(). The gets() function exists purely to conform to ANSI X3.159-1989 (``ANSI C89''). BSD
May 13, 2010 BSD
All times are GMT -4. The time now is 11:50 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy