samples/pidfd/pidfd-metadata.c
Source file repositories/reference/linux-study-clean/samples/pidfd/pidfd-metadata.c
File Facts
- System
- Linux kernel
- Corpus path
samples/pidfd/pidfd-metadata.c- Extension
.c- Size
- 2389 bytes
- Lines
- 121
- Domain
- Support Tooling And Documentation
- Bucket
- samples
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
Dependency Surface
err.herrno.hfcntl.hinttypes.hlimits.hsched.hsignal.hstdio.hstdlib.hstring.hsys/stat.hsys/syscall.hsys/types.hsys/wait.hunistd.h
Detected Declarations
function do_childfunction pidfd_clonefunction sys_pidfd_send_signalfunction pidfd_metadata_fdfunction main
Annotated Snippet
switch (errno) {
case EPERM:
/* Process exists, just not allowed to signal it. */
break;
default:
warn("Failed to signal process\n");
close(procfd);
procfd = -1;
}
}
return procfd;
}
int main(int argc, char *argv[])
{
int pidfd = -1, ret = EXIT_FAILURE;
char buf[4096] = { 0 };
pid_t pid;
int procfd, statusfd;
ssize_t bytes;
pid = pidfd_clone(CLONE_PIDFD, &pidfd);
if (pid < 0)
err(ret, "CLONE_PIDFD");
if (pidfd == -1) {
warnx("CLONE_PIDFD is not supported by the kernel");
goto out;
}
procfd = pidfd_metadata_fd(pid, pidfd);
close(pidfd);
if (procfd < 0)
goto out;
statusfd = openat(procfd, "status", O_RDONLY | O_CLOEXEC);
close(procfd);
if (statusfd < 0)
goto out;
bytes = read(statusfd, buf, sizeof(buf));
if (bytes > 0)
bytes = write(STDOUT_FILENO, buf, bytes);
close(statusfd);
ret = EXIT_SUCCESS;
out:
(void)wait(NULL);
exit(ret);
}
Annotation
- Immediate include surface: `err.h`, `errno.h`, `fcntl.h`, `inttypes.h`, `limits.h`, `sched.h`, `signal.h`, `stdio.h`.
- Detected declarations: `function do_child`, `function pidfd_clone`, `function sys_pidfd_send_signal`, `function pidfd_metadata_fd`, `function main`.
- Atlas domain: Support Tooling And Documentation / samples.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.