1 /* Filename: dpkg_not_running
2 * Purpose: check whether Debian's package management (dpkg) is running
3 * Authors: grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
4 * Bug-Reports: see http://grml.org/bugs/
5 * License: This file is licensed under the GPL v2.
6 *******************************************************************************/
7 // return 0 if it is not running; return 1 if it is running
14 int main(int argc, char *argv[])
16 struct flock fl = { F_WRLCK, SEEK_SET, 0, 0, 0 };
20 if ((fd = open("/var/lib/dpkg/lock", O_RDWR)) == -1) {
24 if (fcntl(fd, F_SETLK, &fl) == -1) {
25 exit(1); // it is running
28 exit(0); // it is not running
34 /* END OF FILE ****************************************************************/