//Here's a simple solution for mesg, which flips the permission of accepting //messages on the current terminal window, using fstat() and fchmod(). //These are the same as stat() and chmod() but work with file //descriptors instead of file names. File descriptor 0 refers to the //terminal. #include int main() { struct stat info; fstat(0, &info); if (info.st_mode & S_IWGRP) fchmod(0, info.st_mode & ~S_IWGRP); else fchmod(0, info.st_mode | S_IWGRP); }