1 |
// $Ximalas$ |
2 |
|
3 |
#include <sys/param.h> |
4 |
#include <sys/types.h> |
5 |
|
6 |
#include <stdio.h> |
7 |
#include <stdlib.h> |
8 |
#include <sysexits.h> |
9 |
#include <unistd.h> |
10 |
|
11 |
int main(int argc, char **argv) |
12 |
{ |
13 |
int sleeptime; |
14 |
|
15 |
setproctitle("starting"); |
16 |
|
17 |
if (argc < 2) { |
18 |
setproctitle("invalid usage"); |
19 |
|
20 |
fprintf(stderr, "Usage: %s <sleeptime-in-seconds>\n", argv[0]); |
21 |
return EX_USAGE; |
22 |
} // if |
23 |
|
24 |
sleeptime = atoi(argv[1]); |
25 |
|
26 |
while (sleeptime > 0) { |
27 |
setproctitle("sleeping for %d second%s", sleeptime, (sleeptime == 1) ? "" : "s"); |
28 |
sleep(1); |
29 |
sleeptime--; |
30 |
} // while |
31 |
|
32 |
setproctitle("finished"); |
33 |
return EX_OK; |
34 |
} // main() |
35 |
|
36 |
// sleep-setproctitle.c |