This paper presents a real-time optimal control scheme based on a total cost index (TCI) by using the so-called extremum seeking control (ESC). The ESC searches the minimum value of a given performance index where the TCI consisting of the operational cost and the effluent quality cost is used as the index. An improved ESC is proposed where a transformed TCI by monotonically increasing function is utilized to improve the convergence property of the ESC while keeping the argument of the optimal point invariant. The feasibility of the ESC is tested for two types of pseudo-anaerobic-oxic process control: one is the return sludge recycle ratio control, and the other is the aeration control for an alternate zone which can be anaerobic or aerobic depending on the influent condition. Simulation study illustrates that the proposed ESC is able to find a near optimal point successfully and the TCI can be reduced by about 2.7 to 3.8% compared with that of a typical operating condition.