...
 
Commits (8)
CFLAGS+=-Wall -O0 -ggdb -ansi -std=c99 -pedantic
CFLAGS+=-Wall -O0 -ggdb -ansi -std=c11 -pedantic
LDFLAGS=-lpthread
OBJECTS=queue.o
......
......@@ -42,7 +42,9 @@
#define MAX_ARGUMENT_LENGTH 16384
#define MAX_NUM_WORKER_THREADS 32
#define strncpyzero(a,b,c) strncpy((a),(b),(c));(a)[(c)-1]='\0';
#define DATETIME_FORMAT_STR "%[email protected]%T"
#define strncpyzero(dest,src,len) strncpy((dest),(src),(len));(dest)[(len)-1]='\0';
/// interpreter to run command lines with
char interpreter[MAX_COMMAND_LENGTH];
......@@ -97,7 +99,25 @@ void update_time_str()
time_t curtime = time(NULL);
struct tm *loctime = localtime(&curtime);
strftime(time_str, MAX_ARGUMENT_LENGTH - 1, "%F-%H-%M-%S", loctime);
strftime(time_str, MAX_ARGUMENT_LENGTH - 1, DATETIME_FORMAT_STR, loctime);
}
time_t starttime;
char etatime_str[MAX_ARGUMENT_LENGTH];
void update_etatime_str()
{
const time_t curtime = time(NULL);
const time_t deltatime = curtime - starttime;
if (deltatime < 60 || cur_command_line < num_threads || cur_command_line < (num_commands >> 3)) {
snprintf(etatime_str, MAX_ARGUMENT_LENGTH - 1, "Uncertain, need more data");
return;
}
const time_t etatime = starttime + deltatime * num_commands / cur_command_line;
struct tm *loctime = localtime(&etatime);
strftime(etatime_str, MAX_ARGUMENT_LENGTH - 1, DATETIME_FORMAT_STR, loctime);
}
void run_command(int id, char *full_command, char *output_prefix)
......@@ -106,6 +126,8 @@ void run_command(int id, char *full_command, char *output_prefix)
char script_name[MAX_ARGUMENT_LENGTH];
char *tempdir_environment = getenv("TMPDIR");
if (tempdir_environment == NULL)
tempdir_environment = getenv("TEMPDIR");
if (tempdir_environment == NULL || tempdir_environment[0] == '\0')
snprintf(script_name, MAX_ARGUMENT_LENGTH - 1, "/tmp/.queue-%d-XXXXXX", getpid());
else
......@@ -289,7 +311,8 @@ void *run_command_function(void *x)
if (be_verbose > 0) {
pthread_mutex_lock(&outputmutex);
update_time_str();
printf("%s [%s]: finished job", output_prefix, time_str);
update_etatime_str();
printf("%s [%s, ETA: %s]: finished job", output_prefix, time_str, etatime_str);
if (be_verbose > 1)
printf(": %s", full_command);
printf("\n");
......@@ -312,7 +335,8 @@ void *run_command_function(void *x)
if (be_verbose > 0) {
pthread_mutex_lock(&outputmutex);
update_time_str();
printf("%s [%s]: num threads still running: %i\n", output_prefix, time_str, num_running_threads);
update_etatime_str();
printf("%s [%s, ETA: %s]: num threads still running: %i\n", output_prefix, time_str, etatime_str, num_running_threads);
pthread_mutex_unlock(&outputmutex);
}
pthread_mutex_unlock(&workermutex);
......@@ -434,6 +458,8 @@ int main(int argc, char *argv[])
return 1;
}
time(&starttime);
/// If there are more than one command to process ...
if (num_commands > 0) {
cur_command_line = 0; ///< start with first command
......
......@@ -14,7 +14,7 @@ remcoch: $(OBJECTS)
style:
LC_ALL=C LANG=C astyle --indent=tab=4 --indent-labels --pad-oper --unpad-paren --keep-one-line-statements --convert-tabs --indent-preprocessor $$(find . -type f -name '*.c')
LC_ALL=C LANG=C astyle --indent=tab=4 --indent-labels --pad-oper --unpad-paren --keep-one-line-statements --convert-tabs --indent-preprocessor $(shell find . -type f -name '*.c')
strip: remcoch
strip $<
......
/* Copyright (c) 2017, Thomas Fischer <[email protected]>
/* Copyright (c) 2017-2018, Thomas Fischer <[email protected]>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
......@@ -24,10 +24,29 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* The purpose of this program is to read a stream of characters from stdin
* and print it on stdout. Characters below code point 32 (so-called 'control
* characters') will be omitted, except for the NUL, TAB, LF, and CR bytes
* (0, 9, 10, 13).
* The program will exit with error code 1 if it cannot write a byte to stdout.
* Otherwise it will exit with error code 0 (no error), even if no byte was
* read or written (such as on empty input).
* Passing '-v' or '-V' as the single argument to this program will print the
* copyright statement.
*/
#include <stdio.h>
int main(int argc, char *argv[])
{
if (argc > 1 && argv[argc - 1][0] == '-' && (argv[argc - 1][1] == 'v' || argv[argc - 1][1] == 'V') && argv[argc - 1][2] == '\0') {
fprintf(stderr, "Copyright (c) 2017-2018, Thomas Fischer <[email protected]>\n\n");
fprintf(stderr, "Released under the so-called '3-clause BSD license'.\n");
fprintf(stderr, "See the source code (remcoch.c) for details.\n");
return 1;
}
/// Read first character
int c = fgetc(stdin);
/// While not at end of file ...
......