💾 Archived View for thrig.me › tech › status-word.c captured on 2024-07-09 at 02:57:13.

View Raw

More Information

⬅️ Previous capture (2023-04-26)

-=-=-=-=-=-=-

// status-word - show the exit status word from a program

#include <sys/wait.h>

#include <err.h>
#include <stdio.h>
#include <unistd.h>

int
main(void)
{
	int status;
	pid_t pid = fork();
	if (pid < 0) err(1, "fork failed");
	if (pid) {
		wait(&status);
		printf("%d %d\n", status, status >> 8);
	} else {
		execlp("false", "false", (char *) 0);
		err(1, "execl failed");
	}
	return 0;
}