python152 python152 - 26 days ago 31
Python Question

os.mknod() fails on MacOS?

Is

os.mknod()
a privileged call on Mac? It always fails with operation not permitted?

In [1]: import os

In [2]: os.mknod("/tmp/test123")
---------------------------------------------------------------------------
OSError Traceback (most recent call last)
<ipython-input-2-1b8032a076af> in <module>()
----> 1 os.mknod("/tmp/test123")

OSError: [Errno 1] Operation not permitted

Answer

From the OSX manpage https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man2/mknod.2.html

Mknod() requires super-user privileges.

Works except from the invalid argument

sudo python -c "import os; os.mknod('/tmp/test123')"
Comments