Exercise: Supporting Multiple Operating Systems

Test your coding skills on supporting multiple operating systems.


In this exercise, your challenge is to develop an application that behaves differently according to the operating system where it runs.

Problem Statement

Go is a multiplatform language but, in some cases, your program requires doing different things depending on the running operating system.

Coding Challenge

Develop a program that displays all running processes (tasks) in your system. Go’s standard library does not provide a function to achieve this. In order to complete this exercise, you’ll need to run an external program to list all running processes; however, the program or options required vary according to the running operating system.

Your program should run one of the following commands according to the operating system:

  • Linux: ps -ef
  • MacOS: ps aux
  • Windows: tasklist

If the program is executed on a different operating system, it should print a message to STDERR saying “OS not supported” and displaying the current operating system.

If you feel stuck, take a look at how you implemented the notification function for your program in This Chapter, or check the runtime package documentation. If you still need help, check the solution review in the next lesson. Good luck!

Get hands-on with 1200+ tech skills courses.