Simple and functional C interview questions. Essential concepts like signal handling, job queue, logging and multi-threading knowledge are required for implementing answers.
Answers are wrapped between // AX part N
and // AX part N end
where X is question number. All files are given to a interviewee with stripping answers.
Files:
main.c
jobs.c
jobs.h
debug.h
Makefile
- Add
job_myjob_destroy
function to free job context &rand_id
inctx1
- If
rand_is
is greater thanUINT8 / 2
then replace it with anotherrand_id
and let it run again. - Add signal handler: when
USR1
receive print all queue'd jobs, whenSIGTERM
ORSIGINT
received free all queue and gradually exit. All unhandled signals should exit immediately. log_helper
should printDEBUG_ID
, filename and line info toLOG_FILE
.- Create multiple threads, pull and run jobs from the queue. Properly lock the queue, process jobs concurrently.
- Create a Makefile which will define a flag for printing logs to
stdout
instead of a file. Also add debug and release build options.
LOG_STDOUT=y make