1

Assuming I have 2 processes running. Is there any way for me to check which process terminates first during reboot/shutdown? From this link, it tells about appending boot to a file. Yet, I still don't know which process is terminated first between my 2 processes. Is there any way for me to do find out? Maybe a bash script or a .conf file. I'm applying this to CentOS, Redhat, Ubuntu, Solaris, HPUX.

1

This might not be accurate. But from what I've tested, we can try to play around with ps.

Write this file.

#include<stdio.h>
#include<stdlib.h>
#include<signal.h>

FILE *file;
char test[1024] = "/home/fikrie/testprogram.txt";
const char* command = "ps -eo pid,comm,lstart,etime,time,args | grep -E '<process that your monitoring> | <second process your monitoring' > /home/fikrie/runtime.txt;

void signal_callback_handler(int signum)
{
   system(command);
   file = fopen(test, "w");
   if(file != NULL)
   {
     fprintf(file,"Caught signal %d\n",signum);
     fclose(file);
   }
   exit(signum);
}

int main()
{
   signal(SIGINT, signal_callback_handler);
   signal(SIGHUP, signal_callback_handler);

   while(1)
   {
     sleep(5);
   }
   return EXIT_SUCCESS;
}

Compile, then make sure it run with the init. Then check if it starts. Kill your test process. Then check into the runtime.txt. You will see how long the process has been running. Take note of the time. Reboot and check the time again. Which ever process have the least time in between, that process is terminate first.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.