[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Error stream not working in time

From: Petr Pisar
Subject: Re: Error stream not working in time
Date: Wed, 24 Feb 2021 15:10:13 +0100

V Tue, Feb 23, 2021 at 07:56:04PM +0530, Ajinkya Rajput napsal(a):
>       Below is code in c language:
> #include<stdio.h>
> int main()
> {
> int n = 0;
> int k = 1 / n;
> return k;
> }
> when we compile with "gcc <filename>.c", we'll see new executable file 
> "a.out" as output.
> on running/execution(./a.out) new file, output will be as below
> ubuntu@ubuntu:~/temp/c$ ./a.out
> Floating point exception (core dumped)
> When we use time for same command, we are getting different, is there any way 
> to get same output?
> ubuntu@ubuntu:~/temp/c$ /usr/bin/time ./a.out 
> Command terminated by signal 8
> 0.00user 0.00system 0:00.10elapsed 0%CPU (0avgtext+0avgdata 940maxresident)k
> 0inputs+0outputs (0major+53minor)pagefaults 0swaps
> if we forwarded time in different file with option provided by time command, 
> then there is nothing in error stream.
> ubuntu@ubuntu:~/temp/c$ /usr/bin/time -o time.txt ./a.out
> ubuntu@ubuntu:~/temp/c$
>   Is there way, we can get output as "Floating point exception (core dumped)" 
> in place of nothing or is this bug?

The "Floating point exception (core dumped)" message is not printed by your
a.out program. It is printed by your shell after exiting the program. You can
verify with strace tool.

If you wrap the ./a.out program with a /usr/bin/time program, then shell won't
print the message because /usr/bin/time program won't terminate with signal
number 8. The shell does not see ./a.out process. It only see /usr/bin/time.

The fact that ./a.out teminated with the signal is announced by /usr/bin/time
with "Command terminated by signal 8" message. It's just a different wording
for the same fact.

Time tool could be changed to attempt to kill itself with the same signal as
the program under time was terminated, but it would be unreliable (not all
signals can be sent from a user space) and it would be confusing because then
the shell would reported that /usr/bin/time crashed, but that was not true.

Simply put, this is not a bug. Instead of checking standard error for messages
of your shell, inspect exit code which is forward by time from the program

-- Petr

Attachment: signature.asc
Description: PGP signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]