zoukankan      html  css  js  c++  java
  • 守护进程之Sessions

    Sessions:A session is a collection of one or more process groups.

    Sessions:是单个或多个进程组的一个集合。

    process establishes a new session by calling the setsid function.
    进程靠调用setsid()创建一个会话。
    #include <unistd.h>
    pid_t setsid(void);

    If the calling process is not a process group leader, this function creates a new session. Three things happen
    如果调用进程不是组长进程,函数setsid()会创建一个新的会话。起到三个作用:
      1.The process becomes the session leader of this new session. (A session leader is the process that creates a session.) 
         调用进程成为新会话的the session leader。A session leader 是创建会话的进程。
         The process is the only process in this new session.
         在新的会话中,调用进程是唯一的进程。
      2.The process becomes the process group leader of a new process group. The new process group ID is the process ID of the calling process.
         调用进程成为新进程组的组长进程。新进程组ID就是调用进程的进程ID。
      3.The process has no controlling terminal. (We'll discuss controlling terminals in the next section.)   
         调用进程没有控制终端。
         If the process had a controlling terminal before calling setsid, that association is broken.
         在调用setsid()之前,如果调用进程有控制终端, 那么调用进程会脱离这个控制终端。

    This function returns an error if the caller is already a process group leader. 

    如果调用进程已经是一个组长进程,则函数返回出错。
    To ensure this is not the case, the usual practice is to call fork and have the parent terminate and the child continue.
    为了避免这种状况发生,通常的做法是调用fork()使父进程终止,子进程继续运行。
    We are guaranteed that the child is not a process group leader, because the process group ID of the parent is inherited by the child,
    我们保证了子进程不是组长进程,因为父进程的进程组ID没有被子进程继承,
    but the child gets a new process ID. Hence, it is impossible for the child's process ID to equal its inherited process group ID.
    而子进程得到一个新进程ID。因此,子进程ID等于它继承的进程组ID是不可能的。

  • 相关阅读:
    django orm 以列表作为筛选条件进行查询
    申请Let's Encrypt通配符HTTPS证书
    redis集群部署及踩过的坑
    MySQL的索引是什么?怎么优化?
    Session管理之超时设置和强制下线
    在MySQL中使用explain查询SQL的执行计划
    基于Docker搭建MySQL主从复制
    这些年一直记不住的 Java I/O
    高并发大容量NoSQL解决方案探索
    php 如何生成静态页
  • 原文地址:https://www.cnblogs.com/polestar/p/2360641.html
Copyright © 2011-2022 走看看