python: os.exec* vs subprocess (intermediate) anthony explains

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 พ.ย. 2024

ความคิดเห็น • 20

  • @rednafi
    @rednafi 4 ปีที่แล้ว +5

    This snippet style videos regarding a specific feature of the language are amazing 🔥

    • @rednafi
      @rednafi 3 ปีที่แล้ว

      @Jaime Armani How is that relevant here? Dafaq is wrong with people these days.

  • @ianchui
    @ianchui 4 ปีที่แล้ว +3

    I've really liked this and the last video (the os.system one). I understand processes a lot more now, know about shell injections, about child processes. Got me curious and so I went out and learned about forking. Super cool stuff >:)

    • @ianchui
      @ianchui 4 ปีที่แล้ว +3

      understanding the sh is just a program that tries to interpret text as commands and just runs programs as sub processes was just *mind blown*
      it makes so much sense

    • @anthonywritescode
      @anthonywritescode  4 ปีที่แล้ว +1

      one project that's often done in college operating system courses is to implement your own shell -- can be kinda fun too!

  • @talalkalai8748
    @talalkalai8748 2 ปีที่แล้ว +1

    Can u explain the under the hood diff btwn "subprocess.run([python , main.py]) vs multiprocessing.Process(target=func)" ? - Do both fork to a python child proc ?

    • @anthonywritescode
      @anthonywritescode  2 ปีที่แล้ว +1

      the latter is intended to be similar to the threading API. the former is always going to start with an effectively unshared memory due to fork+exec on platforms that support it. the latter can use shared memory through the multiprocessing primitives. neither are guaranteed to use fork

  • @adwaith-rajesh
    @adwaith-rajesh 3 ปีที่แล้ว

    How can I use execvp with built-in commands. They don't "seem" to have a file name.

    • @anthonywritescode
      @anthonywritescode  3 ปีที่แล้ว

      what do you mean by "built-in commands"?

    • @adwaith-rajesh
      @adwaith-rajesh 3 ปีที่แล้ว

      @@anthonywritescode like sourse cd

    • @anthonywritescode
      @anthonywritescode  3 ปีที่แล้ว +1

      those are bash builtins, so you'd have to run bash

    • @anthonywritescode
      @anthonywritescode  3 ปีที่แล้ว +1

      but for example, `source` doesn't make sense to "run" it's for modifying a bash environment. cd doesn't make sense to run either, you'd just use `cwd=...`