Home > DeveloperSection > Interviews > What is the use of on_load() in Erlang programming?

Posted on    February-23-2016 6:40 AM

 erlang erlang 
Ratings:
 1 Answer(s)
  318  View(s)
Rate this:

Tarun Kumar

Total Post:107

Points:535
Posted on    February-23-2016 7:40 AM

The on_load directive name is a function which will run automatically whenever a module is loaded. If we use on_load() function then it is not necessary to export the function because when on_load() function will call it will create a newly spawned process (means: it will generate a new process) and the function must return ok if the module is to remain loaded and become callable.It will generate an exception also causes the module to be unloaded.
If the return value is not an atom then a warning error report will be sent to the error logger. and until the on_load() function returns ok the system will not terminated.
Syntax:
-on_load(Function_Name/0).

Don't want to miss updates? Please click the below button!

Follow MindStick