i m looking for a circuit in which a usb can be connected to two cpu via a switch just like KVM switch but the only diffrence is that when one cpu disconnect the usb cable then the switch operated and connect the usb to 2nd cpu.
I have designed a circuit that uses the Fairchild FSUSB30MUX device as just such a USB switch. Part of test tool that permits one USB thumb drive to be toggled between two separate computers.
(Select browser option to view image in new window to see full size)
The circuit above shows how you can monitor the USB Vcc line from one computer to change the status. In this example the Vcc detect signal was fed into a microcontroller which in turn had control of the switch select signal of the USB switch component. Using the microcontroller like this permitted there to be additional methods to flip the switch such as a touch switch. USB port switching between computers also takes some carefully managed time delays so that switching back and forth does not go too fast otherwise the host computer connections will get confused.
Related information in this other answer.