#include #include #include #include #include #include #include const char *_progname; static int send_break(const char *port) { int err; int fd = open(port, O_RDWR|O_NOCTTY|O_NONBLOCK); if (fd < 0) goto fail; tcdrain(fd); do { err = tcsendbreak(fd, 0); } while (err && errno == EAGAIN); if (err) goto fail; close(fd); return 0; fail: fprintf(stderr, "%s: %s: %s\n", _progname, port, strerror(errno)); if (fd >= 0) close(fd); return -1; } int main(int argc, char *argv[]) { _progname = argv[0]; if (argc != 2) { fprintf(stderr, "Usage: %s port\n", _progname); exit(1); } send_break(argv[1]); return 0; }