Simple Shared Memory in C (mmap)

  Рет қаралды 93,187

Jacob Sorber

Jacob Sorber

Күн бұрын

Пікірлер: 51
@44r0n-9
@44r0n-9 4 жыл бұрын
2 minutes for what I'd otherwise have to a watch a 2 hour lecture. Lmao thanks
@crosbytristen1153
@crosbytristen1153 3 жыл бұрын
dont know if anyone gives a damn but if you're bored like me during the covid times you can stream pretty much all of the latest series on InstaFlixxer. I've been watching with my girlfriend during the lockdown :)
@traviszahir2699
@traviszahir2699 3 жыл бұрын
@Crosby Tristen Definitely, been watching on instaflixxer for since november myself :)
@giveaway4002
@giveaway4002 Жыл бұрын
this trick saved me during one assignment, thanks
@RB-gi3zq
@RB-gi3zq 4 жыл бұрын
Me : This video is only 2 minutes. It can't help me Also me after 2 minutes: OMG I GET EVERYTHING NOW
@arby8722
@arby8722 6 жыл бұрын
Man I always love watching these videos, they're great! Any plans on delving into the Linux or Unix kernels? I realise they're obscenely massive, but it might be nice to have a look into perhaps how a small portion of the kernel works (maybe elaborate on Linux device drivers or something, it can be a bit overwhelming).
@JacobSorber
@JacobSorber 6 жыл бұрын
I'm glad you like them. As for the kernel question. Sure. Maybe. Time is always my biggest constraint. So, I tend to make videos about stuff that I'm already playing with while working on other projects. The kernel is a bigger investment with a higher startup cost. But, I really like hacking around in the kernel. So, I'll see what I can do. Probably not in the next few weeks, though.
@ade5324
@ade5324 2 ай бұрын
I just wanted you to know that this "Programming with Processes" series Covered a HUGE knowledge gap in such a short amount of time I'm extremely grateful! Also question: is series complete? does it cover about IPC, Processes, Threads extensively, or is there still some topic to be covered. Please let me know, thanks.
@alexanderzikal7244
@alexanderzikal7244 3 ай бұрын
That can be very useful! 😊
@dakshays6375
@dakshays6375 5 жыл бұрын
You thinking about making videos about File Systems ? I am sure a lot of people that watch your videos are the students that are taking Operating System course. File System is one of major topics in OS course.
@JacobSorber
@JacobSorber 5 жыл бұрын
It's definitely on my list of possible future topics. File systems is a pretty big space. Are there specific things you would like to hear about?
@nutankumari6343
@nutankumari6343 Жыл бұрын
very helpful 🙂
@katecancer5200
@katecancer5200 Жыл бұрын
Love the video
@kaus05
@kaus05 Ай бұрын
Hi, what is the difference in using the shared memory of unix and mmap if there is any ?
@DavidAlsh
@DavidAlsh Жыл бұрын
Can you share memory with a process started via exec()?
@gr3ybrun1x66
@gr3ybrun1x66 2 жыл бұрын
It would be helpful for my operating systems project if it weren't explicitly prohibited by the professors
@leokiller123able
@leokiller123able 3 жыл бұрын
Do we need mutexes or semaphores when editing shared memory?
@JacobSorber
@JacobSorber 3 жыл бұрын
Often, yes. It depends on what your code is doing, but most programs that use shared memory need some sort of synchronization..
@leokiller123able
@leokiller123able 3 жыл бұрын
@@JacobSorber OK thx, very good video btw 👍
@brooksburris8341
@brooksburris8341 3 жыл бұрын
Hey Jacob, thanks for these videos. I had a noob question about this shared memory. How is this different from just allocating a normal block of memory with malloc before the fork? All pointers should have the same values and so can access the same block of memory. What is the advantage to using mmap over this? Is it simply that you don't have to use pointers? Thanks for your time.
@sverkeren
@sverkeren 2 жыл бұрын
Modern hardware and operating systems support virtual vs physical addresses. The same virtual address value in two different processes does not mean they map to the same physical memory address.
@veggieboy1
@veggieboy1 Жыл бұрын
Just to add on to the other comment, the address might appear to be the same, but upon writing to the memory block in the child process you will notice that it is unchanged in the parent process (if the memory was malloc’ed, as you said).
@erbenton07
@erbenton07 Жыл бұрын
I can't get this to play, it always results in "An error occurred. Please try again later", been trying for 2 days - linux firefox 110.0
@metehangul1164
@metehangul1164 4 жыл бұрын
THATS CRAZY USEFULL
@JacobSorber
@JacobSorber 4 жыл бұрын
I know, right?!?
@metehangul1164
@metehangul1164 4 жыл бұрын
@@JacobSorber yes but what about the speed? is mmap faster than the pipes or another interprocessing techniques? İs that the best way to do that? What do you think?
@rafalmichalski4893
@rafalmichalski4893 4 жыл бұрын
What does mean MAP_ANONYMOUS ?
@1nxpired
@1nxpired 6 жыл бұрын
very helpful :)
@JacobSorber
@JacobSorber 6 жыл бұрын
Thanks. Glad you enjoyed it.
@fallout__boy1130
@fallout__boy1130 Жыл бұрын
Carefull with synchronization and race conditions tho
@JacobSorber
@JacobSorber Жыл бұрын
Yep.
@rouinihosni7108
@rouinihosni7108 6 жыл бұрын
Can u make a video about dlls plz.
@JacobSorber
@JacobSorber 6 жыл бұрын
For a specific OS or just in general? A general one or one for Linux/Unix/MacOS would be easy. If you want a windows one, you might have to wait a bit longer. I'm not doing much with Windows, these days.
@rouinihosni7108
@rouinihosni7108 6 жыл бұрын
@@JacobSorber i use windows. but i have no probleme if u explain it on any platform and thx
@JacobSorber
@JacobSorber 6 жыл бұрын
Ok. Sounds good. I'll see what I can do.
@yashmanwani6232
@yashmanwani6232 3 жыл бұрын
Is there a way to have a shared memory between processes that aren't parent/child and yet have it persisted on disk (i.e across reboots)? shm_open shared memories created in /dev/shm get wiped out on reboot.
@chrisschneider7609
@chrisschneider7609 3 жыл бұрын
Is this shared memory available to other processes? Example one C program and one PHP program. I'm looking at creating something that writes to something other than a file and then is picked up by PHP (or another C program) for use in an API. This will happen once a second so don't want to write to a file and the device has eMMC so definitely don't want to write to that file.
@d.sherman8563
@d.sherman8563 Жыл бұрын
Once a second is nothing, there is no reason not to write to file. Another solution would be to send it via a socket if you really need to avoid the file. But again your computer can do billions of operations a second, something done every second is nothing.
@aabdev
@aabdev 3 жыл бұрын
How do ArtMoney program get access to another process memory in the OS?
@JacobSorber
@JacobSorber 3 жыл бұрын
Probably using something like the ptrace API.
@TheNata96
@TheNata96 5 жыл бұрын
error: ‘MAP_ANONYMOUS’ undeclared (first use in this function) A have this problem. Can you tell me how to fix it? I try gcc -std=c99 gcc -std=gnu99 .. thenks..
@JacobSorber
@JacobSorber 5 жыл бұрын
Need more info about your machine and how you're trying to build it.
@TheNata96
@TheNata96 5 жыл бұрын
@@JacobSorber Linux nata-MS-7721 4.15.0-43-generic #46-Ubuntu SMP Thu Dec 6 14:45:28 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux #define _XOPEN_SOURCE 700 #include #include #include #include #include #include #include #include #include #include #define PAGESIZE (1023) #define osAssers(cond,msg) osErrorFatal(cond,msg,__FILE__,__LINE__); void osErrorFatal(bool cond,const char * msg,const char * file,int line){ if(!cond){ perror(msg); fprintf(stderr, "%s:%d ",file,line ); exit(EXIT_FAILURE); } } int main(int argc, char const *argv[]) { int v=5; uint8_t * shared_memory = mmap(NULL ,PAGESIZE, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS ,-1,0); osAssers(MAP_FAILED!=shared_memory,"mmap failed"); shared_memory[1]=34; pid_t ChildPid=fork(); osAssers(ChildPid!=-1,"fork failed"); if(ChildPid==0){ v=10; shared_memory[1]=15; } else{ wait(NULL); } printf("Not shered: %d ",v ); printf("Shared memory: %i ",shared_memory[1] ); return 0; } gcc -std=c99 -o mmap mmap.c
@JacobSorber
@JacobSorber 5 жыл бұрын
@@TheNata96 Try adding "#define _GNU_SOURCE" at the top.
@TheNata96
@TheNata96 5 жыл бұрын
Thank you!!! @@JacobSorber
@MykhailoChynkov
@MykhailoChynkov Жыл бұрын
@@JacobSorber Comment helped me even now)
@NalamalaSaiTeja
@NalamalaSaiTeja 4 жыл бұрын
Y so fast buddy.
@69k_gold
@69k_gold Жыл бұрын
Mmappe
@livequality4578
@livequality4578 3 ай бұрын
Dawg slow down a little, you skip past the results too fast.
@adrenochromeaddict4232
@adrenochromeaddict4232 Жыл бұрын
I get a MAP_ANONYMOUS not defined error, how do I fix this?
How to Map Files into Memory in C (mmap, memory mapped file io)
4:47
SIZE DOESN’T MATTER @benjaminjiujitsu
00:46
Natan por Aí
Рет қаралды 3,5 МЛН
coco在求救? #小丑 #天使 #shorts
00:29
好人小丑
Рет қаралды 30 МЛН
The fork() function in C
11:16
CodeVault
Рет қаралды 392 М.
you will never ask about pointers again after watching this video
8:03
Producer - Consumer Problem in Multi-Threading
25:18
CodeVault
Рет қаралды 117 М.
How processes get more memory. (mmap, brk)
6:50
Jacob Sorber
Рет қаралды 73 М.
Mastering Memory: Allocation Techniques in C, C++, and ARM Assembly
17:05
before you code, learn how computers work
7:05
Low Level
Рет қаралды 521 М.
But, what is Virtual Memory?
20:11
Tech With Nikola
Рет қаралды 311 М.
i wrote my own memory allocator in C to prove a point
5:23
Low Level
Рет қаралды 399 М.
SIZE DOESN’T MATTER @benjaminjiujitsu
00:46
Natan por Aí
Рет қаралды 3,5 МЛН