In a large pot of salted boiling water, cook the spaghetti or linguine according to package instructions until al dente. Reserve 1/2 cup of pasta water, then drain the pasta and set aside.
In a large skillet, heat 2 tablespoons of olive oil over medium heat. Add the sliced onions and 1/2 teaspoon of salt. Cook, stirring occasionally, for about 15-20 minutes until the onions are golden brown and caramelized.
Stir in the sugar and cook for an additional 5 minutes to enhance the caramelization. Add the minced garlic and red pepper flakes, cooking for another 1-2 minutes until fragrant.
Add the cooked pasta to the skillet with the caramelized onions. Pour in the reserved pasta water and the remaining tablespoon of olive oil. Toss everything together until well combined. Adjust seasoning with the remaining salt if needed.
Serve immediately, topped with grated Parmesan cheese and chopped parsley for garnish.