-1

I have an application which runs through a wrapper and submitted as a job on grid (Linux). y task is to monitor the RAM and virtual memory usage of the process and if the process fails due to memory issue, resubmit it again to grid with a higher memory requirement ( using some switch ). I think this can be achieved by invoking a separate thread from the application which watches the main application and in case of failure relaunch the main application. I am seeking for an advice for better solution to this problem.

Thanks Ruchi

Ruchi
  • 693
  • 3
  • 14
  • 27

2 Answers2

0

Thread will not work, since C and C++ mandate that returning from the main function kills all running threads (courtesy Do child threads exit when the parent thread terminates).

You will need to make it another process, perhaps a script that starts the process which then manages your application.

Community
  • 1
  • 1
Karthik T
  • 31,456
  • 5
  • 68
  • 87
  • So can't I do a self relaunch of the application if it fails due to some memory usage issue without user intervention. I can't use any external script/program which is not invoked from the application itself – Ruchi Jun 26 '13 at 07:02
  • @Ruchi I think that is probably so. Cant your wrapper launch a second process? If not you might need to do as rakib is suggesting. You could relaunch a new instance and kill the current one. – Karthik T Jun 26 '13 at 07:22
0

An usuall way of doing it'd be to check when memory allocation fails, i.e malloc(). If malloc() fails that's an indication that, your systems memory is almost full and on that particular case, you can do what you like to do.

rakib_
  • 136,911
  • 4
  • 20
  • 26