Los Angeles — Shelley Malil, an actor who appeared in the film “The 40-Year-Old Virgin,” was sentenced to life in prison with possible parole for the brutal attack on his ex-girlfriend over two years ago.