Section 39B. When a judgment or decree is entered in a contested proceeding seeking equitable relief or on an account or to determine the construction of a will or of any trust instrument or to determine any question as to the powers, rights or duties of any fiduciary under any written instrument or to determine any question with respect to services rendered by any such fiduciary or the compensation of such fiduciary for such services, the probate court may, in its discretion as justice and equity may require, provide that such sums as said court may deem reasonable be paid out of the estate in the hands of such fiduciary to any party to the proceeding on account of counsel fees and other expenses incurred by him in connection therewith. The sums awarded shall be specified in the judgment or decree which may in such case direct that any sum so awarded to any party be paid in whole or in part to his counsel. The probate court, subject to appeal, shall have like powers when entering a judgment or decree after the receipt of a rescript from the supreme judicial or appeals court unless the rescript shall specifically direct otherwise. The counsel of any party to whom an award might be made under this section on account of counsel fees or expenses may file and prosecute in his own name a petition under section thirty-nine A for the payment directly to him of any sum or sums which the court would have power to award the party. A person interested, whose counsel would have standing hereunder or under section thirty-nine A, shall have standing to institute and prosecute a petition for the determination of any sum or sums which the court would have power to award against such person.