CIS-SM practice question 15 of 25

Which one of the following Linux commands can be used by a non root user to return the process ID listening on port 8080?

Full set: 106 questions
Answer options
A: sudo netstat -an -p TCP | grep :8080
B: sudo netstat -anp | grep :8080
C: netstat -anp | grep :8080 Correct answer
D: netstat -an -pid * | grep :8080
Correct Answer:
C. netstat -anp | grep :8080
Explanation

The command netstat -anp | grep :8080 is the correct choice. The netstat command displays network connections. The flag -a shows all sockets, -n displays numerical addresses, and -p shows the Process ID (PID) and name of the program for each socket. A non-root user can execute this command; however, the -p flag will only reveal PID information for processes owned by that user. The grep :8080 command filters the output to isolate the specific port. Options using sudo are incorrect as they execute the command with elevated (root) privileges, which contradicts the "non-root user" constraint specified in the question.

Why Incorrect

A. The sudo command executes the command with root privileges, which is explicitly contrary to the "non-root user" requirement in the question.
B. This option also uses sudo, which requires root privileges and therefore cannot be the correct command for a non-root user acting without privilege escalation.
D. The syntax -pid is not a valid option or argument for the netstat command in standard Linux distributions.

References

1. ServiceNow Product Documentation: The use of netstat -anp for troubleshooting is documented in the context of the Management, Instrumentation, and Discovery (MID) Server, a core ServiceNow component. For example, the command is recommended to check for port conflicts or verify listener status.

Source: ServiceNow Support Knowledge Base, Article ID: KB0752378, "MID Server connection test fails," Section: "Solution."

Source: ServiceNow Support Knowledge Base, Article ID: KB0535145, "Troubleshoot MID Server not connecting," Section: "Check for port conflicts."

2. University Courseware: University-level computer science and operating systems courses often cover standard Linux networking utilities. The functionality of the -p flag to show the PID is standard course material.

Source: Johns Hopkins University, Department of Computer Science, Course 601.229 Computer System Fundamentals, "Lecture 18: Sockets," Slide 29. The slide lists common netstat options, specifying -p to "show program name/pid."

Scroll to Top