Skip to content

Instantly share code, notes, and snippets.

@mike-burns
Created November 8, 2014 04:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mike-burns/b0241188bd6f1d571f8b to your computer and use it in GitHub Desktop.
Save mike-burns/b0241188bd6f1d571f8b to your computer and use it in GitHub Desktop.
Suspend your machine
/* Does not work if apmd(8) is running. */
/* Requires read-write access to /dev/apmctl. */
#include <sys/types.h>
#include <sys/event.h>
#include <sys/time.h>
#include <sys/ioctl.h>
#include <machine/apmvar.h>
#include <fcntl.h>
#include <stdio.h>
#include <err.h>
#define _PATH_APM_CTLDEV "/dev/apmctl"
int
main(int argc, char *argv[])
{
int fd, ret;
if ((fd = open(_PATH_APM_CTLDEV, O_RDWR)) == -1)
err(1, "open");
if ((ret = ioctl(fd, APM_IOC_SUSPEND, NULL)) == -1)
err(1, "ioctl");
printf("ioctl: %i\n", ret);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment