shmdt (BPX1MDT, BPX4MDT) — Detach a shared memory segment

Function

The shmdt service detaches a shared memory segment.

When there are multiple attachers to the same 64 bit memory object from within a process, the shmdt will not detach the storage from the process until all attachers from within the process have issued a detach.

Requirements

Operation Environment
Authorization: Supervisor state or problem state; PSW key 2, 8, or 9
Dispatchable unit mode: Task
Cross memory mode: PASN = HASN
AMODE (BPX1MDT): 31-bit
AMODE (BPX4MDT): 64-bit
ASC mode: Primary mode
Interrupt status: Enabled for interrupts
Locks: Unlocked
Control parameters: All parameters must be addressable by the caller and in the primary address space.

Format

The syntax format is as follows:

AMODE 64 callers use BPX4MDT with the same parameters. The Shared_Memory_Address parameter is a doubleword.

Parameters

Shared_Memory_Address
Supplied parameter
Type:
Integer
Length:
Fullword (doubleword)

The name of a fullword (doubleword) field that contains the starting address of a shared memory segment. This is the Return_value from shmat (BPX1MAT,BPX4MAT). The address returned is 31 bits for AMODE 31 callers and 64 bits for AMODE 64 callers.

Return_value
Returned parameter
Type:
Integer
Length:
Fullword

The name of a fullword in which the shmdt service returns 0 if the request was successful, or -1 if the operation was unsuccessful.

Return_code
Returned parameter
Type:
Integer
Length:
Fullword
The name of a fullword in which the shmdt service stores the return code. The shmdt service returns Return_code only if Return_value is -1. See z/OS UNIX System Services Messages and Codes for a complete list of possible return code values. The shmdt service can return one of the following values in the Return_code parameter:
Return_code Explanation
EINVAL Shared_Memory_Address is not the data segment start address of a shared memory segment attached to the caller's process. The following reason code can accompany the return code: JRBadAddress.
Reason_code
Returned parameter
Type:
Integer
Length:
Fullword

The name of a fullword in which the shmdt service stores the reason code. The shmdt service returns Reason_code only if Return_value is -1. Reason_code further qualifies the Return_code value. See z/OS UNIX System Services Messages and Codes for the reason codes.

Usage notes

  • When a shared memory segment is detached via shmctl(), the process loses access to the associated shared memory. If this is done before a process has finished using all condition variables and mutexes in the detached shared memory segment, unpredictable results will occur in the application, leading to possible hangs and loss of resources. Because a process is implicitly detached from its shared memory attachments when it terminates, most applications should avoid doing any explicit shmdt() calls before terminating.
  • Above the bar, shared memory cannot be used in subspace mode.
  • For a segment of type IPC_SHAREAS, a detach call will not cause the cleanup of the segment's storage within the user address space unless no other processes in the address space are attached to the segment.

Characteristics and restrictions

The caller of the shmdt service is restricted by ownership and read and read-write permissions that are defined by shmget and shmctl Ipc_SET.

Examples

For an example using this callable service, see BPX1MDT (shmdt) example.