1

Which of these is the best practice:

  1. Set umask and create files with appropriate file permissions OR
  2. Create files and then use chmod() to set appropriate file permissions

if we use umask in a thread, does it affect files created in other threads?

I know chmod affects only the file, but is likely to fail, if the files are created by a different user.

MSK
  • 175
  • 1
  • 10
  • 3
    Don't meddle with the umask. Instead just use [`open` or `creat`](http://man7.org/linux/man-pages/man2/open.2.html) passing the permissions you want, and then let the system handle it with the users umask. If you later need a standard C `FILE*`, use [`fdopen`](http://man7.org/linux/man-pages/man3/fdopen.3p.html). – Some programmer dude May 23 '18 at 04:13
  • 1
    "*if we use umask in a thread, does it affect files created in other threads?*" From [the docs](http://man7.org/linux/man-pages/man2/umask.2.html): "*`umask()` sets the calling process's file mode creation mask ...*" So yes, it affects **all** threads of a process. – alk May 23 '18 at 04:41
  • @Someprogrammerdude: Can i create files with the required permissions, wont it masked by the umask bits? – MSK May 23 '18 at 14:02
  • 2
    The user might have set the umask for a reason. Don't meddle with it. – Some programmer dude May 24 '18 at 08:54

0 Answers0