I made a website that needs to execute some kind of C++ program (the program has been compiled). But I want to limit the resources needed by the program. The resources that I want to limit are run time and used memory.
I think run time can be done with command to execute & sleep time; kill $!
But that command causes some delay if the process finishes before the sleep time.

I don't know how to limit run time (without delay) and used memory with an inline command.
Is there any suggestion to do it?