No video

How Does LibC Detect Redirection? Interesting Bug Follow Up.

  Рет қаралды 10,024

Jacob Sorber

Jacob Sorber

2 жыл бұрын

Patreon ➤ / jacobsorber
Courses ➤ jacobsorber.th...
Website ➤ www.jacobsorbe...
---
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.jacobsorbe...
people.cs.clem...
persist.cs.clem...
To Support the Channel:
+ like, subscribe, spread the word
+ contribute via Patreon --- [ / jacobsorber ]
Source code is also available to Patreon supporters. --- [jsorber-youtub...]

Пікірлер: 37
@SourabhBhat
@SourabhBhat 2 жыл бұрын
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 жыл бұрын
I had the same question, thank you for asking !
@JacobSorber
@JacobSorber 2 жыл бұрын
You're welcome. Thanks for giving me an excuse to track it down.
@unperrier5998
@unperrier5998 2 жыл бұрын
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 жыл бұрын
We must admire how smart GCC/CLang is for a program of several MBs.
@japroz
@japroz 2 жыл бұрын
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 жыл бұрын
All the best👍💯
@JacobSorber
@JacobSorber 2 жыл бұрын
Cool. Hopefully, I'll see you in class. Best of luck.
@japroz
@japroz 2 жыл бұрын
@@JacobSorber which course do u teach ?
@JacobSorber
@JacobSorber 2 жыл бұрын
@@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 жыл бұрын
New video request: what does the "restrict" keyword mean in C?
@unperrier5998
@unperrier5998 2 жыл бұрын
Thanks Jacob. In your video about TTY, I'd like a refresher on line discipline if you don't mind. Thanks in advance.
@umpoucosobreconhecimentos
@umpoucosobreconhecimentos 2 жыл бұрын
Thanks for sharing this video. Very useful
@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.
@cernejr
@cernejr 2 жыл бұрын
Interesting video, I have learned something. Thank you.
@taylorh1883
@taylorh1883 2 жыл бұрын
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.
@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."
@sanya5881
@sanya5881 2 жыл бұрын
Do you have gdb running on Apple silicon?
@nathanoy_
@nathanoy_ 8 ай бұрын
Why does it segfault at the end?
@Tystros
@Tystros 2 жыл бұрын
For some reason, comments I write here seem to disappear...
@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 KZbin. Yours truly Leslie Satenstein
@voytechj
@voytechj 2 жыл бұрын
"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 жыл бұрын
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.
@SuperCape
@SuperCape 2 жыл бұрын
muhlloc
@SlideRSB
@SlideRSB 2 жыл бұрын
Interesting that you were in incognito mode for your Google search. What are you hiding. 🤔
@ahmadhadwan
@ahmadhadwan 2 жыл бұрын
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 жыл бұрын
😂🤔 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';
What's the Best Way to Copy a Struct in C and C++?
13:44
Jacob Sorber
Рет қаралды 33 М.
How I Did The SELF BENDING Spoon 😱🥄 #shorts
00:19
Wian
Рет қаралды 35 МЛН
Joker can't swim!#joker #shorts
00:46
Untitled Joker
Рет қаралды 37 МЛН
Кадр сыртындағы қызықтар | Келінжан
00:16
How to Check Your Pointers at Runtime
14:12
Jacob Sorber
Рет қаралды 31 М.
Make your Data Type more Abstract with Opaque Types in C
13:41
Jacob Sorber
Рет қаралды 49 М.
everything is open source if you can reverse engineer (try it RIGHT NOW!)
13:56
Low Level Learning
Рет қаралды 1,3 МЛН
The Inline Keyword in C.
16:18
Jacob Sorber
Рет қаралды 57 М.
How to measure memory usage inside my program? (getrusage)
13:08
Jacob Sorber
Рет қаралды 30 М.
The What, How, and Why of Void Pointers in C and C++?
13:12
Jacob Sorber
Рет қаралды 52 М.
Making variables atomic in C
11:12
Jacob Sorber
Рет қаралды 36 М.
Setup Tips for Your Next Programming Project
12:33
Jacob Sorber
Рет қаралды 28 М.
Object-Oriented Programming is Bad
44:35
Brian Will
Рет қаралды 2,3 МЛН
How I Did The SELF BENDING Spoon 😱🥄 #shorts
00:19
Wian
Рет қаралды 35 МЛН