public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/66202] New: Weird behaviour when fork and printf without newline are being used
@ 2015-05-19 13:20 nichlas_severinsen at hotmail dot com
  2015-05-19 14:14 ` [Bug c/66202] " tkoenig at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: nichlas_severinsen at hotmail dot com @ 2015-05-19 13:20 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66202

            Bug ID: 66202
           Summary: Weird behaviour when fork and printf without newline
                    are being used
           Product: gcc
           Version: 4.9.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: nichlas_severinsen at hotmail dot com
  Target Milestone: ---

Created attachment 35566
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=35566&action=edit
visbug.c and notvisbug.c, described in the post

Hi, I'm rather new so tear me apart. Not really sure what to put on severity.
GCC VERSION: 4.9.2 (Ubuntu 4.9.2-10ubuntu13)
UNAME: Linux 3.19.0-16-generic #16-Ubuntu SMP x86_64 GNU/Linux

I'll try to explain what I've bumped into, but I may be wrong, so please ravage
me if this is my fault.

Attached are two C files (in a .tar.gz because I'm only allowed to add one
attachment..), the only difference between them is that "notvisbug.c" uses the
'\n' character in its printf function calls. The other attachment "visbug.c"
does not.

I've compiled them with "gcc visbug.c -o visbug" and "gcc notvisbug.c -o
notvisbug". (and ran them in a cli with ./name, of course)

What they essentially do (or should do) is create a process tree looking
something like this, using fork(), and each process except main also prints out
who they are; "I am X":

Main
  |
  A
 / \
 B  C
 |
 D

notvisbug.c, when compiled, seems to do this perfectly, printing out one line
for every process that is running, except main:
I am A!
I am B!
I am D!
I am C!
visbug.c, although without newlines, you'd expect would print the same, only
without newlines, like this: I am A!I am B!I am D!I am C!
It does not, instead it prints this: 
I am A!n@Computer:~/dev$ I am A!I am B!I am A!I am B!I am D!I am A!I am C!
(or something similiar, the two first A's seem to repeats itself, but the rest
come and go in different sequences)

I have looked at the assembly code generated with this version of GCC and found
that notvisbug uses callputs while visbug uses callprintf to print the strings,
I also read here http://cs.lmu.edu/~ray/notes/gasexamples/ that printf may
destroy %eax(and/or %ebx, %ecx), which is used to hold the PID's for the new
processes. (tell me if you need to see the assembly files (.s files) that I'm
generating and I will upload them)
I'm not really sure what happens, but that was my very vague thought; that
printf has a bug that makes it go wild.

I'm probably wrong though. Apologies if this is the wrong place to post this.

Thanks for reading, anyway.


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug c/66202] Weird behaviour when fork and printf without newline are being used
  2015-05-19 13:20 [Bug c/66202] New: Weird behaviour when fork and printf without newline are being used nichlas_severinsen at hotmail dot com
@ 2015-05-19 14:14 ` tkoenig at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2015-05-19 14:14 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66202

Thomas Koenig <tkoenig at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
                 CC|                            |tkoenig at gcc dot gnu.org
         Resolution|---                         |INVALID

--- Comment #1 from Thomas Koenig <tkoenig at gcc dot gnu.org> ---
This is a bug tracker for gcc. Your problem appears to be with details of the
interaction of fork() with C's standard I/O, which is more of a general
programming question. Your question would be more appropriate in several other
forums, for example the Usenet newgroup comp.unix.programmer or
stackoverflow.com


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-05-19 14:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-19 13:20 [Bug c/66202] New: Weird behaviour when fork and printf without newline are being used nichlas_severinsen at hotmail dot com
2015-05-19 14:14 ` [Bug c/66202] " tkoenig at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).