异想天开

What's the true meaning of light, Could you tell me why

Python OS模块

日期:2015-07-14 15:23:57
  
最后更新日期:2015-07-14 16:03:36
Python 2.6.6的os模块函数接口
[code lang="cpp"]
abort() 结束进程
access(path, mode) 用当前权限测试访问文件
chdir(path) 改变当前目录
chmod(path, mode) 改变权限
chown(path, uid, gid) 改变uid,gid
chroot(path) 设置root目录
close(fd) 关闭fd
closerange(fd_low, fd_high) 关闭一段范围的fd,忽略错误
confstr(name) 获得系统配置项值
ctermid() 获得控制终端名
dup(fd) 拷贝一个fd
dup2(old_fd,new_fd) 使new_fd成为old_fd的拷贝
execl(file, *args) 执行可执行文件file(全路径),使用参数args
execle(file, *args, env) 同上,不过加上环境变量env
execlp(file, *args) 同上,不过file的路径位于$PATH
execlpe(file, *args, env) 同execle
execv(path, args)
execve(path, args, env)
execvp(file, args)
execvpe(file, args, env)
fchdir(fildes) 改变当前目录到fildes指向的目录
fchmod(fd, mode) 改变fd所指向的文件的mode
fchown(fd, uid, gid) 改变fd所指向的文件的uid,gid
fdatasync(fildes) 强制刷新fildes所指向的文件
fdopen(fd [, mode='r' [, bufsize]]) 得到fd的file object
fork() fork进程
forkpty() fork进程,同时使用新的伪终端
fpathconf(fd, name) Return the configuration limit name for the file descriptor fd.
fstat(fd) Like stat(), but for an open file descriptor
fstatvfs(fd) Perform an fstatvfs system call on the given fd
fsync(fildes) force write of file with filedescriptor to disk
ftruncate(fd, length) Truncate a file to a specified length
getcwd() Return a string representing the current working directory
getcwdu() Return a unicode string representing the current working directory
getegid() Return the current process's effective group id
getenv(key, default=None) 获得环境变量key
geteuid() 获得进程有效uid
getgid() 获得进程gid
getgroups() Return list of supplemental group IDs for the process
getloadavg() 得到最近1分钟,5分钟,15分钟操作系统就绪队列的平均进程个数
getlogin() Return the actual login name
getpgid(pid) Call the system call getpgid()
getpgrp() Return the current process group id
getpid() 获得进程pid
getppid() 获得父进程pid
getsid(pid) Call the system call getsid()
getuid() Return the current process's user id
isatty(fd) Return True if the file descriptor 'fd' is an open file descriptor connected to the slave end of a terminal
kill(pid, sig) 发送sig信号给pid进程
killpg(pgid, sig) 发送信号sig给pgid进程组
lchown(path, uid, gid) Change the owner and group id of path to the numeric uid and gid,This function will not follow symbolic links
link(src, dst) Create a hard link to a file
listdir(path) Return a list containing the names of the entries in the directory
lseek(fd, pos, how) Set the current position of a file descriptor
lstat(path) Like stat(path), but do not follow symbolic links
major(device) Extracts a device major number from a raw device number
makedev(major, minor) Composes a raw device number from the major and minor device numbers
makedirs(path [, mode=0777]) 创建目录,同时可以创建中间目录,若不存在时
minor(device) Extracts a device minor number from a raw device number
mkdir(path [, mode=0777]) Create a directory
mkfifo(filename [, mode=0666]) Create a FIFO (a POSIX named pipe)
mknod(filename [, mode=0600, device]) Create a filesystem node (file, device special file or named pipe) named filename
nice(inc) Decrease the priority of process by inc and return the new priority
open(filename, flag [, mode=0777]) 打开文件
openpty() Open a pseudo-terminal, returning open fd's for both master and slave end
pathconf(path, name) Return the configuration limit name for the file or directory path
pipe() 创建管道
popen(command [, mode='r' [, bufsize]]) Open a pipe to/from a command returning a file object
popen2(cmd, mode='t', bufsize=-1) 同上,不过返回值为(child_stdin, child_stdout)
popen3(cmd, mode='t', bufsize=-1) 返回值为(child_stdin, child_stdout, child_stderr)
popen4(cmd, mode='t', bufsize=-1) 返回值为(child_stdin, child_stdout)
putenv(key, value) Change or add an environment variable
read(fd, buffersize) Read a file descriptor
readlink(path) Return a string representing the path to which the symbolic link points
remove(path) Remove a file (same as unlink(path))
removedirs(path)
rename(old, new) Rename a file or directory
renames(old, new) 重新命名,文件路径中某个目录不存在时,有权限则创建它
rmdir(path) Remove a directory
setegid(gid) Set the current process's effective group id
seteuid(uid) Set the current process's effective user id
setgid(gid) Set the current process's group id
setgroups(list) Set the groups of the current process to list
setpgid(pid, pgrp) Call the system call setpgid()
setpgrp() Make this process the process group leader
setregid(rgid, egid) Set the current process's real and effective group ids
setreuid(ruid, euid) Set the current process's real and effective user ids
setsid() Call the system call setsid()
setuid(uid) Set the current process's user id
spawnl(mode, file, *args)
Execute file with arguments from args in a subprocess.
If mode == P_NOWAIT return the pid of the process.
If mode == P_WAIT return the process's exit code if it exits normally;
otherwise return -SIG, where SIG is the signal that killed it
spawnle(mode, file, *args, env)
Execute file with arguments from args in a subprocess with the
supplied environment.
If mode == P_NOWAIT return the pid of the process.
If mode == P_WAIT return the process's exit code if it exits normally;
otherwise return -SIG, where SIG is the signal that killed it
spawnlp(mode, file, *args)
Execute file (which is looked for along $PATH) with arguments from
args in a subprocess with the supplied environment.
If mode == P_NOWAIT return the pid of the process.
If mode == P_WAIT return the process's exit code if it exits normally;
otherwise return -SIG, where SIG is the signal that killed it
spawnlpe(mode, file, *args, env)
Execute file (which is looked for along $PATH) with arguments from
args in a subprocess with the supplied environment.
If mode == P_NOWAIT return the pid of the process.
If mode == P_WAIT return the process's exit code if it exits normally;
otherwise return -SIG, where SIG is the signal that killed it
spawnv(mode, file, args)
Execute file with arguments from args in a subprocess.
If mode == P_NOWAIT return the pid of the process.
If mode == P_WAIT return the process's exit code if it exits normally;
otherwise return -SIG, where SIG is the signal that killed it
spawnve(mode, file, args, env)
spawnvp(mode, file, args)
spawnvpe(mode, file, args, env)
stat(path) Perform a stat system call on the given path
stat_float_times([newval]) Determine whether os.[lf]stat represents time stamps as float objects
statvfs(path) Perform a statvfs system call on the given path
strerror(code) Translate an error code to a message string
symlink(src, dst) Create a symbolic link pointing to src named dst
sysconf(name) Return an integer-valued system configuration variable
system(command) 执行command命令
tcgetpgrp(fd) Return the process group associated with the terminal given by a fd
tcsetpgrp(fd, pgid) Set the process group associated with the terminal given by a fd
tempnam([dir[, prefix]]) 得到一个临时文件名
times() 得到进程(utime, stime, cutime, cstime, elapsed_time)的元组
tmpfile() 创建临时文件,该临时文件不会有目录项
umask(new_mask) 设置屏蔽码
uname() -> (sysname, nodename, release, version, machine)
unlink(path) 移除一个文件
unsetenv(key) 删除环境变量key
urandom(n) 获得n个随机字节
utime(path, (atime, mtime)) 设置文件的atime和mtime,若第二个参数为None,则设置当前时间
wait() 等待子进程执行完成
wait3(options)
wait4(pid, options)
waitpid(pid, options) 等待pid进程完成
walk(top, topdown=True, onerror=None, followlinks=False) Directory tree generator,返回一个3元组dirpath, dirnames, filenames
write(fd, string) 将string写入fd

[/code]