How Does LibC Detect Redirection? Interesting Bug Follow Up.

Поділитися
Вставка
  • Опубліковано 31 січ 2022
  • Patreon ➤ / jacobsorber
    Courses ➤ jacobsorber.thinkific.com
    Website ➤ www.jacobsorber.com
    ---
    How Does LibC Detect Redirection? Interesting Bug Follow Up. // This video follows up on my custom allocator bug video, this time looking at how the program (specifically LibC) knows about redirection (or that the output has been redirected). Does it? We know the allocator behaves differently. In this video we look into the libC source code and learn a bit more about stat and IO block sizes.
    Related Videos:
    Redirection Bug Video: • An Interesting Redirec...
    ***
    Welcome! I post videos that help you learn to program and become a more confident software developer. I cover beginner-to-advanced systems topics ranging from network programming, threads, processes, operating systems, embedded systems and others. My goal is to help you get under-the-hood and better understand how computers work and how you can use them to become stronger students and more capable professional developers.
    About me: I'm a computer scientist, electrical engineer, researcher, and teacher. I specialize in embedded systems, mobile computing, sensor networks, and the Internet of Things. I teach systems and networking courses at Clemson University, where I also lead the PERSIST research lab.
    More about me and what I do:
    www.jacobsorber.com
    people.cs.clemson.edu/~jsorber/
    persist.cs.clemson.edu/
    To Support the Channel:
    + like, subscribe, spread the word
    + contribute via Patreon --- [ / jacobsorber ]
    Source code is also available to Patreon supporters. --- [jsorber-youtube-source.heroku...]

КОМЕНТАРІ • 37

  • @SourabhBhat
    @SourabhBhat 2 роки тому +32

    Very interesting way of optimising memory. Thank you so much. I really appreciate the time and effort taken by you to answer the question.

    • @mr.mirror1213
      @mr.mirror1213 2 роки тому +3

      I had the same question, thank you for asking !

    • @JacobSorber
      @JacobSorber  2 роки тому +6

      You're welcome. Thanks for giving me an excuse to track it down.

  • @unperrier5998
    @unperrier5998 2 роки тому +15

    On Redhat derivatives, the debug version of the glibc package will allow you to view symbols and source code while in a C library function, inside gdb.

  • @georgecop9538
    @georgecop9538 2 роки тому +11

    We must admire how smart GCC/CLang is for a program of several MBs.

  • @japroz
    @japroz 2 роки тому +7

    Nice video. I will be applying to Clemson University this year for undergrad admission just because of Jacob Sorber. Pray for me

    • @saptakbhoumik8446
      @saptakbhoumik8446 2 роки тому +2

      All the best👍💯

    • @JacobSorber
      @JacobSorber  2 роки тому +1

      Cool. Hopefully, I'll see you in class. Best of luck.

    • @japroz
      @japroz 2 роки тому

      @@JacobSorber which course do u teach ?

    • @JacobSorber
      @JacobSorber  2 роки тому +1

      @@japroz Operating Systems, and occasionally a few others.

    • @japroz
      @japroz 2 роки тому

      @@JacobSorber great, well, I hope I get accepted there and would love to meet you physically

  • @teaguehall17
    @teaguehall17 2 роки тому +8

    New video request: what does the "restrict" keyword mean in C?

  • @umpoucosobreconhecimentos
    @umpoucosobreconhecimentos 2 роки тому +1

    Thanks for sharing this video. Very useful

  • @cernejr
    @cernejr 2 роки тому

    Interesting video, I have learned something. Thank you.

  • @unperrier5998
    @unperrier5998 2 роки тому +1

    Thanks Jacob.
    In your video about TTY, I'd like a refresher on line discipline if you don't mind.
    Thanks in advance.

  • @rcookman
    @rcookman 2 роки тому

    I have always had problems with custom allocators in my classes, but I don't think we are talking about the same thing.

  • @sanya5881
    @sanya5881 Рік тому

    Do you have gdb running on Apple silicon?

  • @lsatenstein
    @lsatenstein 2 роки тому

    Hi Jacob,
    Thank you for this presentation. I wonder if there is an easier way to determine redirection.
    For example, with your method, what do you get if you do redirection to /dev/null? Are the numbers the same? I would expect that printf() string formatting would not take need to take place, as there is no need for any output whatsoever.
    I thought of evaluating FILE * for stdout to see if it varies from the non redirected output. The only issue is that redirection was already setup before the program executed. This leads to the following question:
    Can one get access to the full command line to see if redirection is in effect?
    On a second subject that I, a great-grandfather to be, has for you. It is about RUST. I am hoping that you take an interest in it to present an on-line course on cargo/rust. I am hoping that it is something that you have already started to prepare.
    My personal opinion is that you have to teach Rust to a class to learn the best way to present Rust on UA-cam.
    Yours truly
    Leslie Satenstein

    • @voytechj
      @voytechj 2 роки тому +1

      "man isatty" and in your program include "unistd.h" and call function "isatty(fileno(stdout))". It returns 0 if there was redirection to a file or piped to another process.

    • @kyrylmelekhin2667
      @kyrylmelekhin2667 2 роки тому +1

      Rust is a mistake. The mother of all bloat, which it stems from. Don't believe me? Then try building it from source yourself.

    • @Hauketal
      @Hauketal 2 роки тому

      There is no command line necessary to start a program. Any program can do that.
      Also "redirection" is a red herring, lots of programs never had any console in their ancestry to inherit from. The question is about the type of device in the OS connected to a FILE*.

    • @lsatenstein
      @lsatenstein 2 роки тому

      @@kyrylmelekhin2667 The compiled code is not bloat. It is using the compiler, mainly to trap malloc/free errors. I generally do that with Valgrind. I also do multiple path testing. Perhaps C could adopt one or two of Rust's strict rules for sharing. I think it could be done by having a type extension for xxx* variables (void *, char*, struct *...)

    • @anon_y_mousse
      @anon_y_mousse 2 роки тому

      @@kyrylmelekhin2667 Most newer languages require you to download a ton of things to work with them. If your system didn't come pre-installed with C you'd have to download quite a bit to get it working. Not to mention all the libraries written in it for the various programs you use. The real problem with Rust isn't that it's any more or less bloated, but the fact that they want to rewrite everything in it even when you have perfectly functioning code in C. This leads to future bugs because new developers don't know the reason behind doing things and loss of features because they just haven't gotten around to implementing it yet. Though, to be fair, Rust does require more as a starting point than a lot of other newer languages.

  • @niklasmertsch3032
    @niklasmertsch3032 2 роки тому

    I first encountered this with apt (Debian/Ubuntu package manager): `apt list` writes a list of all available packages to stdout. `apt list | grep ...` does the same thing, but also writes a warning to stderr: "WARNING: apt does not have a stable CLI interface. Use with caution in scripts."

  • @taylorh1883
    @taylorh1883 2 роки тому +1

    Hey! In a lot of your videos, when using make you refer to older tutorials for more information. Have you considered making an updated make video? Watching the older ones, there are a lot of things not covered and your videos are such high quality!

    • @JacobSorber
      @JacobSorber  2 роки тому

      Yeah, I could do that. Are there specific topics you would like to see?

    • @taylorh1883
      @taylorh1883 2 роки тому

      @@JacobSorber I'm not 100% on what there is fully, but I see the power of make having briefly used it from some of your tutorials. I know you roughly touched on for loops in make in one of your videos. Maybe that bash / make syntax could be useful. I was just thinking a more in depth rehash of the original stuff you made though.

    • @JacobSorber
      @JacobSorber  2 роки тому

      @@taylorh1883 Ok. I'll see what I can do. Thanks.

  • @nathanoy_
    @nathanoy_ 8 місяців тому

    Why does it segfault at the end?

  • @Tystros
    @Tystros 2 роки тому

    For some reason, comments I write here seem to disappear...

  • @SuperCape
    @SuperCape 2 роки тому

    muhlloc

  • @SlideRSB
    @SlideRSB 2 роки тому +1

    Interesting that you were in incognito mode for your Google search. What are you hiding. 🤔

    • @ahmadhadwan
      @ahmadhadwan 2 роки тому +3

      I typically do that when searching about topics i don't want to get recommendations of. If you searched in your browser about any topic, for the next couple weeks all you going to get is recommendations about it.

    • @JacobSorber
      @JacobSorber  2 роки тому +2

      😂🤔 nothing...

  • @anon_y_mousse
    @anon_y_mousse 2 роки тому

    I've run into this issue in the distant past where a bug would occur as a result of redirection, and the general consensus is to use isatty() in unistd.h on *nix systems to test if it's a pipe. It doesn't always work, though. Also, you can still redirect stderr: ./prog 2>&1 | grep 'some error message';