Compilation:
Code: Select all
gcc -Wall -Wextra -O2 -g -I /usr/include/ImageMagick/ -o pingblob pingblob.c -lMagickCore -lpng -ljpeg -ltiff -lbz2 -lz -lm -lpthread
or (animated!): http://www.changethethought.com/wp-cont ... o1_500.gif
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <sys/stat.h>
#include <wand/MagickWand.h>
int main(int argc, char** argv)
{
if (argc != 2) {
fprintf(stderr, "usage: %s <path>\n", argv[0]);
return 1;
}
char* path = argv[1];
int fd = open(path, O_RDONLY);
if (fd < 0) {
fprintf(stderr, "open(%s) %d, %s\n", path, errno, strerror(errno));
return 1;
}
struct stat st;
if (fstat(fd, &st)) {
fprintf(stderr, "stat(%s) %d, %s\n", path, errno, strerror(errno));
return 1;
}
size_t pos = 0, size = st.st_size;
char* data = (char*)malloc(size);
while (pos < size) {
int r = read(fd, data + pos, size - pos);
if (r < 0) {
if (errno == EINTR) continue;
fprintf(stderr, "read(%s) %d, %s\n", path, errno, strerror(errno));
return 1;
}
pos += r;
}
close(fd);
MagickCoreGenesis(".", MagickFalse);
while (1) {
ImageInfo* ii = CloneImageInfo(NULL);
ExceptionInfo ei;
GetExceptionInfo(&ei);
Image* img = PingBlob(ii, data, size, &ei);
DestroyImageInfo(ii);
fprintf(stderr, "PingBlob: %d, %s, %s\n",
ei.severity, ei.reason, ei.description);
DestroyExceptionInfo(&ei);
if (!img) break;
fprintf(stderr, "PingBlob: %s, %lu x %lu, %lu COLORS, %lu DEPTH\n",
img->magick, img->magick_columns, img->magick_rows, img->colors, img->depth);
DestroyImage(img);
usleep(10000);
}
free(data);
MagickCoreTerminus();
return 0;
}
Code: Select all
$ while true ; do ps cux | grep pingblob ; sleep 1s ; done
521 24386 8.0 0.1 31196 19856 pts/107 S+ 22:28 0:00 pingblob
521 24386 8.0 0.2 48404 36996 pts/107 R+ 22:28 0:00 pingblob
521 24386 8.3 0.3 66164 54756 pts/107 S+ 22:28 0:00 pingblob
521 24386 8.5 0.4 83924 72516 pts/107 S+ 22:28 0:00 pingblob
521 24386 8.6 0.5 101272 89864 pts/107 S+ 22:28 0:00 pingblob
521 24386 8.6 0.6 118756 107416 pts/107 S+ 22:28 0:00 pingblob
521 24386 8.5 0.7 136104 124764 pts/107 S+ 22:28 0:00 pingblob
521 24386 8.6 0.8 153724 142316 pts/107 S+ 22:28 0:00 pingblob
521 24386 8.5 0.9 171212 159872 pts/107 S+ 22:28 0:00 pingblob
521 24386 8.7 1.0 188972 177632 pts/107 S+ 22:28 0:00 pingblob
521 24386 8.6 1.1 206316 195024 pts/107 R+ 22:28 0:00 pingblob
521 24386 8.6 1.2 224076 212736 pts/107 S+ 22:28 0:01 pingblob
521 24386 8.6 1.4 241836 230496 pts/107 S+ 22:28 0:01 pingblob
521 24386 8.6 1.5 259600 248256 pts/107 S+ 22:28 0:01 pingblob
521 24386 8.6 1.6 277220 265812 pts/107 S+ 22:28 0:01 pingblob
521 24386 8.6 1.7 294704 283364 pts/107 S+ 22:28 0:01 pingblob
521 24386 8.7 1.8 312328 300920 pts/107 S+ 22:28 0:01 pingblob
521 24386 8.6 1.9 329812 318472 pts/107 S+ 22:28 0:01 pingblob
521 24386 8.2 2.0 347848 336476 pts/107 R+ 22:28 0:01 pingblob
521 24386 8.2 2.1 365608 354200 pts/107 S+ 22:28 0:01 pingblob
521 24386 8.3 2.2 383368 371960 pts/107 S+ 22:28 0:01 pingblob
521 24386 8.3 2.3 400852 389512 pts/107 S+ 22:28 0:01 pingblob
521 24386 8.3 2.4 418200 406860 pts/107 R+ 22:28 0:02 pingblob