首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
您找到你想要的搜索结果了吗?
是的
没有找到

利用python socket管理服务器

os.setsid() #该方法做一系列的事:首先它使得该进程成为一个新会话的领导者,接下来它将进程转变一个新进程组的领导者,最后该进程不再控制终端, 运行的时候,建立一个进程,linux会分配个进程号。然后调用os.fork()创建子进程。若pid>0就是自己,自杀。子进程跳过if语句, 通过os.setsid()成为linux中的独立于终端的进程(不响应sigint,sighup等) umask的作用:#默认情况下的 umask值是022(可以用umask命令查看),此时你建立的文件默认权限是644(6-0,6-2,6-2),建立的目录的默认 权限是755(7-0,7-2,7-2),可以用ls -l验证一下哦 现在应该知道umask的用途了,它是为了控制默认权限,不要使默认的文件和目录具有全权而设的

02

Python和sendfile[通俗易懂]

sendfile(2) is a UNIX system call which provides a “zero-copy” way of copying data from one file descriptor (a file) to another (a socket). Because this copying is done entirely within the kernel, sendfile(2) is more efficient than the combination of “file.read()” and “socket.send()”, which requires transferring data to and from user space. This copying of the data twice imposes some performance and resource penalties which sendfile(2) syscall avoids; it also results in a single system call (and thus only one context switch), rather than the series of read(2) / write(2) system calls (each system call requiring a context switch) used internally for the data copying. A more exhaustive explanation of how sendfile(2) works is available here, but long story short is that sending a file with sendfile() is usually twice as fast than using plain socket.send(). Typical applications which can benefit from using sendfile() are FTP and HTTP servers.

01
领券