Is malloc deterministic? Say If I have a forked process, that is, a replica of another process, and at some point both of them call the malloc
Yes, it's deterministic to some degree, but not that doesn't necessarily mean it'll given identical results in two forks of a process.
Just for example, the Single Unix Specification says: "[...] to avoid errors, the child process may only execute async-signal-safe operations until such time as one of the exec functions is called."
For better or worse, malloc is not in the list of "async-signal-safe" functions.
This limitation is in a section that discusses multithreaded programs, but doesn't specify whether the limitation applies only to multithreaded programs, or also applies to single threaded programs.
Conclusion: you can't count on malloc producing identical results in the parent and the child. If the program is multithreaded, you can't count on malloc working at all in the child, until it has called exec--and there's room for reasonable question whether it's actually guaranteed to work even in a single-threaded child before the child calls exec.
References: