非常感谢你的回答。
fd=open( filename,O_WRONLY | O_CREAT,0644);
我这边生成的文件权限是 -rw------- root root 1036800 2014-08-27 09:06 lu
不是-rw-r--r-- 所以很迷惑![/quote]
因为你的umask是0077或者0066啊,
自己用umask命令看看就知道啦
0644 & ~0077 = 0600
UMASK(2) Linux Programmer’s Manual UMASK(2)
NAME
umask - set file mode creation mask
SYNOPSIS
#include <sys/types.h>
#include <sys/stat.h>
mode_t umask(mode_t mask);
DESCRIPTION
umask() sets the calling process’s file mode creation mask (umask) to mask & 0777 (i.e., only the file permis-
sion bits of mask are used), and returns the previous value of the mask.
The umask is used by open(2), mkdir(2), and other system calls that create files to modify the permissions
placed on newly created files or directories. Specifically, permissions in the umask are turned off from the
mode argument to open(2) and mkdir(2).
The constants that should be used to specify mask are described under stat(2).
The typical default value for the process umask is S_IWGRP | S_IWOTH (octal 022). In the usual case where the
mode argument to open(2) is specified as:
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH
(octal 0666) when creating a new file, the permissions on the resulting file will be:
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH
(because 0666 & ~022 = 0644; i.e., rw-r--r--).
RETURN VALUE
This system call always succeeds and the previous value of the mask is returned.
CONFORMING TO
SVr4, 4.3BSD, POSIX.1-2001.
实际生成的文件的权限还要受到进程的权限掩码的影响的
O_CREAT
If the file exists, this flag has no effect except as noted under O_EXCL below. Otherwise, the file is created; the user ID of the file is set to the effective user ID of the process; the group ID of the file is set to the group ID of the file's parent directory or to the effective group ID of the process; and the access permission bits (see <sys/stat.h>) of the file mode are set to the value of the third argument taken as type mode_t modified as follows: a bitwise-AND is performed on the file-mode bits and the corresponding bits in the complement of the process' file mode creation mask. Thus, all bits in the file mode whose corresponding bit in the file mode creation mask is set are cleared. When bits other than the file permission bits are set, the effect is unspecified. The third argument does not affect whether the file is open for reading, writing or for both.