gpt4 book ai didi

c - 调用 execve() 时环境的各个方面是根据什么保留的?

转载 作者:行者123 更新时间:2023-11-30 19:01:36 25 4
gpt4 key购买 nike

我知道exec应该替换整个进程镜像,但我也知道在调用 exec 之一时会保留一些内容,例如文件描述符。 -家庭功能。

调用execve()时,环境的各个方面是在什么基础上保持的? ?

最佳答案

来自execve(3):

All process attributes are preserved during an execve(), except the following:

  • The dispositions of any signals that are being caught are reset to the default (signal(7)).

  • Any alternate signal stack is not preserved (sigaltstack(2)).

  • Memory mappings are not preserved (mmap(2)).

  • Attached System V shared memory segments are detached (shmat(2)).

  • POSIX shared memory regions are unmapped (shm_open(3)).

  • Open POSIX message queue descriptors are closed (mq_overview(7)).

  • Any open POSIX named semaphores are closed (sem_overview(7)).

  • POSIX timers are not preserved (timer_create(2)).

  • Any open directory streams are closed (opendir(3)).

  • Memory locks are not preserved (mlock(2), mlockall(2)).

  • Exit handlers are not preserved (atexit(3), on_exit(3)).

  • The floating-point environment is reset to the default (see fenv(3)).

POSIX 也强制执行此操作(尽管被否定):

The new process shall inherit at least the following attributes from the calling process image:

  • Nice value (see nice())

  • semadj values (see semop())

  • Process ID

  • Parent process ID

  • Process group ID

  • Session membership

  • Real user ID

  • Real group ID

  • Supplementary group IDs

  • Time left until an alarm clock signal (see alarm())

  • Current working directory

  • Root directory

  • File mode creation mask (see umask())

  • File size limit (see getrlimit() and setrlimit())

  • Process signal mask (see pthread_sigmask())

  • Pending signal (see sigpending())

  • tms_utime, tms_stime, tms_cutime, and tms_cstime (see times())

  • Resource limits

  • Controlling terminal

  • Interval timers

The initial thread of the new process shall inherit at least the following attributes from the calling thread:

  • Signal mask (see sigprocmask() and pthread_sigmask())

  • Pending signals (see sigpending())

All other process attributes defined in this volume of POSIX.1-2017 shall be inherited in the new process image from the old process image. All other thread attributes defined in this volume of POSIX.1-2017 shall be inherited in the initial thread in the new process image from the calling thread in the old process image. The inheritance of process or thread attributes not defined by this volume of POSIX.1-2017 is implementation-defined.

关于c - 调用 execve() 时环境的各个方面是根据什么保留的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57581393/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com