• utopiah@lemmy.ml
    link
    fedilink
    arrow-up
    3
    ·
    4 hours ago

    I have some of her paper zines on my desk, warmly recommended.

    Might look esoteric at first but if you think we will be using Linux at least on desktop, servers, consoles and more for decades then totally worth learning about.

  • rumba@lemmy.zip
    link
    fedilink
    English
    arrow-up
    13
    ·
    7 hours ago

    You used to be able to sudo cat /proc/kcore > /dev/dsp and listen to your ram

  • communism@lemmy.ml
    link
    fedilink
    arrow-up
    5
    ·
    7 hours ago

    Julia Evans has a bunch of these really handy cheatsheets. I have several saved that I reference semi-regularly.

  • four@lemmy.zip
    link
    fedilink
    English
    arrow-up
    40
    ·
    23 hours ago

    I’m surprised it doesn’t mention that /proc/self automagically points to the directory of the current process. So if you’re writing a program, you can just look there for information about itself

  • otacon239@lemmy.world
    link
    fedilink
    arrow-up
    56
    ·
    1 day ago

    Okay, this is legitimately cool as heck. This finally helps me wrap my head around the “everything is a file” concept in Linux. Of course it can just copy the executable to memory for later reference. That’s how the system would not completely have a meltdown when you do live updates.

    Excellent share!

    • atzanteol@sh.itjust.works
      link
      fedilink
      English
      arrow-up
      52
      ·
      1 day ago

      It’s a bit more interesting than that…

      Linux, unlike Windows, will let you delete a file that is actively in use. It removes the reference on the file system but the contents of the file won’t be deleted until all file pointers to it close. In fact it will still be seen as taking up disk space until it’s garbage collected (deleting a large file that’s in use can be frustrating).

      So the file is actually still available to that running process. If you replace it with a new executable and run that then you get the new version.

    • HiddenLayer555@lemmy.ml
      link
      fedilink
      English
      arrow-up
      14
      ·
      edit-2
      21 hours ago

      I bet this is done with inodes. Deleted files aren’t truely deleted until nothing has it open and its inode gets dropped. Like ARC for files.

      You can also do interesting things like overwrite a “file” (as in a specific filesystem path) with new contents while keeping anything that already has the file open on the old contents by unlinking the old inode to the path and writing the new contents under a new inode. I believe mv does this. The kind of lesser known feature that probably strikes a good balance between preventing super annoying silent errors/corruption and causing them.

      Relevant Kevin Fang video

      • AlteredEgo@lemmy.ml
        link
        fedilink
        arrow-up
        1
        ·
        15 hours ago

        Thanks for explaining, I was wondering about that.

        Wait, is that why renaming or moving files on android takes forever?

        • diaphragmwp@discuss.tchncs.de
          link
          fedilink
          English
          arrow-up
          5
          ·
          15 hours ago

          No, that’s because Android. It’s also overlaying all filesystems to enforce stupid rules, like no files named “CON” and no files named the same in a different case (like in DOS).

  • PowerCrazy@lemmy.ml
    link
    fedilink
    English
    arrow-up
    11
    ·
    21 hours ago

    I didn’t know any of this. Amazing. I usually just look at /proc/net/ for routes and bonding config etc.

    • redjard@reddthat.com
      link
      fedilink
      arrow-up
      8
      ·
      20 hours ago

      Also known as zombie files. If you are unlucky they can take up all space on a drive, or even tmpfs (so your ram) and you can’t easily find them. At least until you end the right process or restart.
      Had that happen once and had to write my own script to trace it to the log of an open terminal emulator tab that had billions of lines.

    • Shadow@lemmy.ca
      link
      fedilink
      arrow-up
      24
      ·
      1 day ago

      If you delete a file that’s still open by the app, the link in proc will still exist and you can copy the file back out of proc.

      • RustySharp@programming.dev
        link
        fedilink
        arrow-up
        7
        ·
        1 day ago

        Does that not make them a hard link (pointing to a filesystem node) instead of a symlink (pointing to another filename)?

        • Shadow@lemmy.ca
          link
          fedilink
          arrow-up
          22
          ·
          1 day ago

          No, you can’t have a hard link cross filesystems and proc is its own fs type.

              • SlurpingPus@lemmy.world
                link
                fedilink
                arrow-up
                5
                ·
                21 hours ago

                These days there can be a dozen virtual filesystems doing various stuff. If you ever want to get quite baffled, install a terminal emulator on an Android phone (not Termux) and run mount.

                • Shadow@lemmy.ca
                  link
                  fedilink
                  arrow-up
                  5
                  ·
                  23 hours ago

                  It still is! If you try and boot a kernel with nothing in /dev, you won’t get most of the kernel boot messages since /dev/console doesn’t exist. You need a basic set of device nodes in /dev before udev is started.

                  If you’re going to rsync a system to new hardware and exclude /dev /proc /sys, it’s better to setup a new mount of your / to a different directory and sync off that, so you get the underlying stuff without the cruft.

  • jaybone@lemmy.zip
    link
    fedilink
    English
    arrow-up
    8
    ·
    24 hours ago

    I’m aware of /proc but usually use lsof to find open fd’s for a process.

    Is one better than the other?

  • pelya@lemmy.world
    link
    fedilink
    arrow-up
    14
    ·
    1 day ago

    Do you know how to build portable executables?

    configure --prefix=/proc/self/pwd
    

    It even works in .so files and libtool.

      • pelya@lemmy.world
        link
        fedilink
        arrow-up
        11
        ·
        1 day ago

        The executable will search for .so files not inside predefined paths like /usr/lib but inside it’s current directory. You may theoretically put . as an argument to configure, but it converts that into an absolute path, snd libtool and linker fail when encountering relative paths inside shared library dependencies.

      • pelya@lemmy.world
        link
        fedilink
        arrow-up
        8
        ·
        1 day ago

        --prefix=$(pwd) is resolved at compile time. If you move your compiled .so files to a different directory, they stop working.

        • eleijeep@piefed.social
          link
          fedilink
          English
          arrow-up
          2
          ·
          1 day ago

          I see what you mean, very clever solution if a program is using the configure prefix by compiling it into the binary.

          That can’t be very common though is it? Usually the configure prefix is just used by make install to install the binaries into the prefix. If the compiled program needs to know where it is installed it can read argv[0].

          Have you seen this used somewhere?

          • pelya@lemmy.world
            link
            fedilink
            arrow-up
            5
            ·
            1 day ago

            I am using this myself in Android app, where you can write files only inside /data/data/your.app.id/

            So naturally, if you want to publish a different app, your.app.id will be different, so you need to recompile all your Linux tools that you bundle inside your app.

            If you are not running your Linux tools on Android, you’d probably be better off using Docker or a chroot.