posix — 가장 일반적인 POSIX 시스템 호출


이 모듈은 C 표준과 POSIX 표준(얇게 위장한 유닉스 인터페이스)에 의해 표준화된 운영 체제 기능에 대한 액세스를 제공합니다.

가용성: Unix.

Do not import this module directly. Instead, import the module os, which provides a portable version of this interface. On Unix, the os module provides a superset of the posix interface. On non-Unix operating systems the posix module is not available, but a subset is always available through the os interface. Once os is imported, there is no performance penalty in using it instead of posix. In addition, os provides some additional functionality, such as automatically calling putenv() when an entry in os.environ is changed.

에러는 예외로 보고됩니다; 보통 예외는 형 에러로 인한 것입니다만, 시스템 호출 때문에 보고되는 에러는 OSError를 발생시킵니다.

대용량 파일 지원

여러 운영 체제(AIX 와 Solaris 포함)는 intlong이 32비트 값인 C 프로그래밍 모델로 인한 2 GiB보다 큰 파일에 대한 지원을 제공합니다. 이것은 일반적으로 관련 크기 및 오프셋 형을 64비트 값으로 정의하여 수행됩니다. 이러한 파일을 때로 대용량 파일 (large files)이라고 합니다.

off_t의 크기가 long보다 크고 long long이 적어도 off_t만큼 크면 파이썬에서 대용량 파일 지원이 활성화됩니다. 이 모드를 활성화하려면 특정 컴파일러 플래그로 파이썬을 구성하고 컴파일해야 할 수도 있습니다. 예를 들어, Solaris 2.6과 2.7에서는 다음과 같은 작업이 필요합니다:

CFLAGS="`getconf LFS_CFLAGS`" OPT="-g -O2 $CFLAGS" \
        ./configure

대용량 파일을 사용할 수 있는 리눅스 시스템에서, 이렇게 할 수 있습니다:

CFLAGS='-D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64' OPT="-g -O2 $CFLAGS" \
        ./configure

주목할만한 모듈 내용

In addition to many functions described in the os module documentation, posix defines the following data item:

posix.environ

인터프리터가 시작될 때 문자열 환경을 나타내는 딕셔너리. 키와 값은 유닉스에서는 바이트열이고 윈도우에서는 str입니다. 예를 들어, environ[b'HOME'](윈도우에서는 environ['HOME'])은 홈 디렉터리의 경로명이며, C의 getenv("HOME")와 동등합니다.

이 딕셔너리를 수정해도 execv(), popen() 또는 system()에 전달되는 문자열 환경에는 영향을 주지 않습니다; 환경을 변경해야 하는 경우 environexecve()로 전달하거나, system() 이나 popen()의 명령 문자열에 변수 대입과 export 문장을 추가하십시오.

버전 3.2에서 변경: 유닉스에서, 키와 값은 바이트열입니다.

참고

The os module provides an alternate implementation of environ which updates the environment on modification. Note also that updating os.environ will render this dictionary obsolete. Use of the os module version of this is recommended over direct access to the posix module.