473,794 Members | 2,738 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

runtime error to stderr or ? (gcc ubuntu bash)

$ ./test_fail
1
Floating point exception
- but this leaves 'somefile' zero size

$ ./test_fail 1>somefile
Floating point exception
- and this leaves 'somefile' zero size

$ ./test_fail 2>somefile
1
Floating point exception
- why doesn't 'Floating point exception' go to stderr?

#include <stdio.h>

int main(){
printf("%d\n",1 );
printf("%d\n",2/0);
return 0;
}

Jul 20 '08 #1
10 4454
On Sat, 19 Jul 2008 20:45:05 -0700 (PDT), Isaac Gouy
<ig****@yahoo.c omwrote:
>$ ./test_fail
1
Floating point exception
- but this leaves 'somefile' zero size

$ ./test_fail 1>somefile
Floating point exception
- and this leaves 'somefile' zero size

$ ./test_fail 2>somefile
1
Floating point exception
- why doesn't 'Floating point exception' go to stderr?

#include <stdio.h>

int main(){
printf("%d\n",1 );
printf("%d\n",2/0);
return 0;
}

Since there are no floating point objects and no floating point
operations in your code at all, you probably need to ask in a group
that discusses your system to determine why you are getting a floating
point exception.

What is the point of passing a command line argument to a program that
doesn't use it?
Remove del for email
Jul 20 '08 #2
On Jul 20, 12:04*pm, Barry Schwarz <schwa...@dqel. comwrote:
What is the point of passing a command line argument to a program that
doesn't use it?
Isaac,
He meas to say that ./test_fail 2>somefile does not do the redirection
but passes 2>somefile as an argument. What you needed was ./test_fail
2somefile. And of course, you should not be getting FPE as there are
no floating points. Further, in C99, 2/0.0 or 2.0/0 or 2.0/0.0 should
be yielding inf.
Jul 20 '08 #3
In article <7e************ *************** *******@u12g200 0prd.googlegrou ps.com>
Isaac Gouy <ig****@yahoo.c omwrote:
[when running a program that deliberately divides by zero:]
>$ ./test_fail 2>somefile
1
Floating point exception
- why doesn't 'Floating point exception' go to stderr?
There is no requirement that any internal diagnostics printed by
the C runtime system go anywhere in particular (perhaps they might
go to a system log, for instance). This is an example of "undefined
behavior": the C Standard imposes no requirements, so any system
can do whatever it wants.

<off-topic>
In this particular case, the reason that the string "Floating point
exception" is not redirected is that it is not produced by the
process that runs ./test_fail or anything that it invokes. Instead,
it is being produced by the command-interpreter itself.

You can see this by telling the command interpreter to
run another command interpreter, redirecting this sub-interpreter's
error output. However, a bit of a trick is required:

$ bash -c './test_fail; true' >out 2>err
$ cat out
$ cat err
bash: line 1: 28106 Floating point exception./test_fail
$

The "; true" is required, at least on my Linux box. (Actually
any command should suffice.)
</off-topic>
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: gmail (figure it out) http://web.torek.net/torek/index.html
Jul 20 '08 #4
Isaac Gouy <ig****@yahoo.c omwrites:
$ ./test_fail
1
Floating point exception
- but this leaves 'somefile' zero size

$ ./test_fail 1>somefile
Floating point exception
- and this leaves 'somefile' zero size

$ ./test_fail 2>somefile
1
Floating point exception
- why doesn't 'Floating point exception' go to stderr?
For the full story (I don't know it) ask in comp.unix.progr ammer but
the short one is that that message is not coming from your program.
#include <stdio.h>

int main(){
printf("%d\n",1 );
printf("%d\n",2/0);
return 0;
}
--
Ben.
Jul 20 '08 #5
Thank you all.

- on my systems, actually this /does/ do redirection

$ ./test_fail 1>somefile
On Jul 20, 1:14 am, Chris Torek <nos...@torek.n etwrote:
There is no requirement that any internal diagnostics printed by
the C runtime system go anywhere in particular (perhaps they might
go to a system log, for instance). This is an example of "undefined
behavior": the C Standard imposes no requirements, so any system
can do whatever it wants.
That's what I needed to know, thanks.
On Jul 20, 12:50 am, rahul <rahulsin...@gm ail.comwrote:
And of course, you should not be getting FPE as there are
no floating points. Further, in C99, 2/0.0 or 2.0/0 or 2.0/0.0 should
be yielding inf.
On Jul 20, 1:14 am, Chris Torek <nos...@torek.n etwrote:
In this particular case, the reason that the string "Floating point
exception" is not redirected is that it is not produced by the
process that runs ./test_fail or anything that it invokes. Instead,
it is being produced by the command-interpreter itself.
I suppose we could speculate that the command-interpreter is failing
to handle inf.
Incidentally, I was using test_fail to check that a script was
correctly capturing stderr from another process and just couldn't
figure out what was wrong with the script - when of course there
wasn't anything on stderr for the script to show :-)
Jul 20 '08 #6
In article <49************ *************** *******@p31g200 0prf.googlegrou ps.com>,
Isaac Gouy <ig****@yahoo.c omwrote:
>In this particular case, the reason that the string "Floating point
exception" is not redirected is that it is not produced by the
process that runs ./test_fail or anything that it invokes. Instead,
it is being produced by the command-interpreter itself.
>I suppose we could speculate that the command-interpreter is failing
to handle inf.
The command interpreter doesn't handle the value at all. Dividing by
zero produces undefined behaviour: on your system, the behaviour is
that the program gets a "floating point exception" signal (even though
there is no floating point involved). The command interpreter
recognises that the program exited because of that signal, and prints
out the message.

-- Richard
--
Please remember to mention me / in tapes you leave behind.
Jul 20 '08 #7
On Sun, 20 Jul 2008 00:50:52 -0700 (PDT), rahul
<ra*********@gm ail.comwrote:
>On Jul 20, 12:04*pm, Barry Schwarz <schwa...@dqel. comwrote:
>What is the point of passing a command line argument to a program that
doesn't use it?
Isaac,
He meas to say that ./test_fail 2>somefile does not do the redirection
but passes 2>somefile as an argument. What you needed was ./test_fail
2somefile. And of course, you should not be getting FPE as there are
no floating points. Further, in C99, 2/0.0 or 2.0/0 or 2.0/0.0 should
be yielding inf.
No, I have no idea if his shell is smart enough to take the as a
token or not. However, regardless, he is passing a command line
argument (either "2" or "2>somefile ") and his program makes no attempt
to process it.
Remove del for email
Jul 20 '08 #8
Barry Schwarz <sc******@dqel. comwrites:
On Sun, 20 Jul 2008 00:50:52 -0700 (PDT), rahul
<ra*********@gm ail.comwrote:
>>On Jul 20, 12:04Â*pm, Barry Schwarz <schwa...@dqel. comwrote:
>>What is the point of passing a command line argument to a program that
doesn't use it?
Isaac,
He meas to say that ./test_fail 2>somefile does not do the redirection
but passes 2>somefile as an argument. What you needed was ./test_fail
2somefile. And of course, you should not be getting FPE as there are
no floating points. Further, in C99, 2/0.0 or 2.0/0 or 2.0/0.0 should
be yielding inf.

No, I have no idea if his shell is smart enough to take the as a
token or not. However, regardless, he is passing a command line
argument (either "2" or "2>somefile ") and his program makes no attempt
to process it.
There is nothing for the program to process. argc will be 1 in all
the cases shown.

--
Ben.
Jul 20 '08 #9
Barry Schwarz <sc******@dqel. comwrites:
On Sat, 19 Jul 2008 20:45:05 -0700 (PDT), Isaac Gouy
<ig****@yahoo.c omwrote:
>>$ ./test_fail
1
Floating point exception
- but this leaves 'somefile' zero size

$ ./test_fail 1>somefile
Floating point exception
- and this leaves 'somefile' zero size

$ ./test_fail 2>somefile
1
Floating point exception
- why doesn't 'Floating point exception' go to stderr?

#include <stdio.h>

int main(){
printf("%d\n",1 );
printf("%d\n",2/0);
return 0;
}

Since there are no floating point objects and no floating point
operations in your code at all, you probably need to ask in a group
that discusses your system to determine why you are getting a floating
point exception.

What is the point of passing a command line argument to a program that
doesn't use it?
<OT>
He's not passing a command line argument to the program.

His command lines are:

./test_fail

which passes no arguments;

./test_fail 1>somefile

which passes no arguments and redirects stdout to "somefile" (the "1"
could have been omitted); and

./test_fail 2>somefile

which passes no arguments and redirects stderr to "somefile".

This is the correct syntax for the Bourne shell and shells derived
from it, such as ksh, bash, and zsh. The numbers 1 and 2 refer to the
file descriptor numbers corresponding to stdout and stderr,
respectively. There's no requirement for whitespace before or after
the ">", and it's common to omit it.

</OT>

So, his question is why the "Floating point exception" message still
appears when he redirects both stdout and stderr to a file.

The answer is system-specific. In this case, I think the message is
not part of the *program's* output; instead, it appears to be
generated by the shell, after the program has terminated. (A quick
experiment on a Linux system shows that the message doesn't appear if
the same program is invoked from a Perl script, implying that it's the
shell that prints the message.)

And yes, it's a bit odd that an integer division results in a
"Floating point exception" message, but since the C standard doesn't
define the behavior of division by zero, this is well within the
bounds of permitted behavior.

One plausible way this might happen is this:

The division caused the program to be killed by a SIGFPE signal.
This information was propagated to the invoking program (the
shell) in the status returned by system() (or whatever the shell
used to invoke the program). The shell responded by printing this
message to *its* stderr, which is not affected by the redirection
of the program's stderr.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jul 20 '08 #10

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

Similar topics

2
3159
by: Tony | last post by:
bash-2.03# /configure --with-apxs=/usr/local/apache/bin/apxs --with-zlib=/usr /local --with-db3=/opt/sfw --with-openssl=/usr/local/ssl/ --enable-module=so loading cache ./config.cache checking host system type... i386-pc-solaris2.8 checking for gcc... gcc checking whether the C compiler (gcc ) works... yes checking whether the C compiler (gcc ) is a cross-compiler... no checking whether we are using GNU C... yes checking whether gcc...
17
5128
by: abdur_rab7 | last post by:
Hi, I am compiling code for nanosleep in CYGWIN. During compilation i get the following error Socket.cc: In method `bool Socket::hangOnConnection(int = 0)': Socket.cc:338: aggregate `struct timespec tmsp' has incomplete type and cannot b e initialized
2
2115
by: etienne | last post by:
Hello, I'm trying to compile this C++ code with gcc 3.4.5 under Solaris/SPARC (from a complete application, the file is : FullLinkedList.hh) but the make fails (no problem when compiling under ubuntu/x86) : (from line 330 to 481) /***************************************************************************** * ITERATOR SECTION - INNER CLASSES
21
5250
by: Paul Edwards | last post by:
I have written a public domain (not GPL etc) C runtime library (PDPCLIB) for DOS, OS/2 and MVS. You can see it here: http://sourceforge.net/projects/pdos/ I now wish to port it to Win32, so that I can create executables to run under Windows 98 command prompt where every byte of the executable is from public domain code. I'm only interested in writing strictly conforming C89 programs,
21
6898
by: one2001boy | last post by:
PostMessage() function returns ERROR_NOT_ENOUGH_QUOTA after running in a loop for 700 times, but the disk space and memory are still big enough. any suggestion to resolve this problem? thanks.
6
8617
by: Rares Vernica | last post by:
Hi, I am using tr1/unordered_map in my code. My code compiled ok on g++ (GCC) 4.1.2 (Ubuntu 4.1.2-0ubuntu1). Now I need to compile my code on g++ (GCC) 4.0.3 (Ubuntu 4.0.3-1ubuntu5). I get a messy error. Here are what I try to do: typedef unordered_map<string, unsignedStringHash;
5
2244
by: lanclot | last post by:
hi i am trying to authenticate a user using ClientLogin by sending a post to https://www.google.com/accounts/ClientLogin in my c program use ssl and socket the next code is my request: sprintf(request, "POST /accounts/ClientLogin HTTP/1.0\r\nContent-type: application/x-www-form-urlencoded\r\nContent-length:1357\r \nEmail=myemail@sina.com&Passwd=mypasswd&service=lh2&source=sd-aa-1.0\r \n");
7
7273
by: neha_chhatre | last post by:
hello im writing a c program in ubuntu, im using the function log2f(float) float stands for a float value.... im getting the following error neha@neha:~/midi$ gcc twinkle_formula.c twinkle_formula.c: In function 'main': twinkle_formula.c:129: warning: incompatible implicit declaration of
2
6364
by: akhilesh.noida | last post by:
I am trying to compile glibc-2.5 for ARM based board. But I am getting errors while configuring it. Please check and give your inputs for resolving this. configure command : $ ../glibc-2.5/configure --prefix=/mnt/new/Mars/glibc_HQ_test/GLIBC/ install/ --with-__thread --enable-kernel=2.6.11 --enable-shared
0
9671
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9518
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
10433
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
10212
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
10161
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,...
0
9035
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
4112
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
2
3720
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2919
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.