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.cjobs.cjobs.hdebug.hMakefile
- Add
job_myjob_destroyfunction to free job context &rand_idinctx1 - If
rand_isis greater thanUINT8 / 2then replace it with anotherrand_idand let it run again. - Add signal handler: when
USR1receive print all queue'd jobs, whenSIGTERMORSIGINTreceived free all queue and gradually exit. All unhandled signals should exit immediately. log_helpershould 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
stdoutinstead of a file. Also add debug and release build options.
LOG_STDOUT=y make