Pcwd(3PROC) Process Control Library Functions Pcwd(3PROC)

Pcwd, Pcwd_freeget process current working directory information

Process Control Library (libproc, -lproc)

#include <libproc.h>

int
Pcwd(struct ps_prochandle *P, prcwd_t **cwdp);

void
Pcwd_free(prcwd_t *cwd);

The () function obtains the current working directory and related information about the file system it is contained upon of the process handle P. This information is synthesized for live processes and is obtained from the NT_CWD elf note for core files. It is not supported on handles that refer to idle (PS_IDLE) processes.

The library will allocate the memory needed for a prcwd_t structure. A pointer to this data will be stored in cwdp. It is the callers responsibility to release it by calling the () function and passing it back in the cwd argument. The allocated data stored in cwdp has a lifetime independent of the process handle, P. In other words, the data in cwdp may be used after someone has called Prelease(3PROC) or Pfree(3PROC) on P.

The prcwd_t structure is defined in <sys/procfs.h> and discussed in more detail in core(5). The various path related strings are NUL-terminated character strings that may not be valid in the calling process's locale.

Upon successful completion, the Pwcd() function returns and stores the allocated prcwd_t structure in cwdp. Otherwise is returned and errno is set to indicate the error.

The Pcwd() functions will fail if:

An underlying memory allocation failed.
The process handle, P, refers to a core file which does not contain the NT_CWD ELF note.
The process handle P, does not support obtaining the current working directory. This would happen because the process handle does not refer to a core file or live process.

Additional errors may be generated based on the type of process handle that is present.

See in libproc(3LIB).

pwdx(1), libproc(3LIB), core(5), proc(5)

May 10, 2024 OmniOS