The invention provides a control device, a
machine tool, a control method, and a
computer program product, which can prevent tools from colliding with each other when the tools are conveyed among a plurality of tool magazines without arranging a detection part in an accommodating part. The control device controls the first tool
magazine, the second tool
magazine and the tool conveying device, and when the empty second accommodating part is arranged at the second replacement position, the execution tool moves from the first tool
magazine to the second tool magazine, and when the execution tool moves from the second tool magazine to the first tool magazine, the control device executes the following steps: in the first tool magazine, the first tool magazine is replaced with the second tool magazine; moving the designated first accommodating part to a first replacement position; conveying the tool from the first replacement position to the second replacement position using the tool conveying device after the first process is executed; after the second
processing is executed, in the second tool magazine, the second containing part located at the position except for the second replacement position is moved to the second replacement position; after the third process is executed, the tool is conveyed from the second replacement position to the first replacement position using the tool conveying device.