my 4gb hp pendrive is not getting detected

Pen drives can fail at any time and they are so relatively cheap there's little point in struggling to get one working again. Just bin it and buy a new one.

I am sorry if that means you will lose important data but you should not use a pen drive for such data unless it's already backed up somewhere else.