The most analogous approach under Linux would be to use the NVCtrl API which is what nvidia-settings
, the linux NVIDIA control panel application, provides.
How to download the nvidia-settings source package is documented in the linux driver release notes. Specifically, you can find various packages for specific driver versions here
Choose a package that is closest to your driver version.
Once you have downloaded and unzipped the nvidia-settings source, you will find a samples
directory. In that directory is a sample program which has the necessary framework for what you want. Specifically, look in nv-control-targets.c
. The following function in that file will do what you want:
/* Connected Display Devices on GPU */
ret = XNVCTRLQueryTargetAttribute(dpy,
NV_CTRL_TARGET_TYPE_GPU,
gpu, // target_id
0, // display_mask
NV_CTRL_CONNECTED_DISPLAYS,
&display_devices);
if (!ret) {
fprintf(stderr, "Failed to query connected displays\n");
return 1;
}
printf(" Display Device Mask (Connected) : 0x%08x\n",
display_devices);
Note that there are some preparatory/setup function calls at the top of that program (nv-control-targets.c
) that will need to be executed as well.
There is also a function (Display Mode) in NVML (nvidia-smi is based on NVML) that will inform you of whether the GPU is hosting a display or not, but I'm not sure it gives you the granularity you want.
Actually, upon re-reading your question, NVML Display Mode might be sufficient for what you want. Referring to the API documentation here, p46:
7.10.2.10 nvmlReturn_t DECLDIR nvmlDeviceGetDisplayMode (nvmlDevice_t device, nvmlEnableState_t
display)
Retrieves the display mode for the device.
For Tesla ™and Quadro ®products from the Fermi and Kepler families.
This method indicates whether a physical display is currently connected to the device.
See nvmlEnableState_t for details on allowed modes.
Parameters:
device The identifier of the target device
display Reference in which to return the display mode
Returns:
• NVML_SUCCESS if display has been set
• NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized
• NVML_ERROR_INVALID_ARGUMENT if device is invalid or display is NULL
• NVML_ERROR_NOT_SUPPORTED if the device does not support this feature