28. Trace Process Service Ownership
Beginner Mode
Start your terminal to use beginner mode.
Scenario
A process is consuming excessive resources, but its origin is unclear.
Task
Create a utility script at /home/devops/trace_service.sh that accepts a PID argument and outputs its managing systemd service name, full status, and the last 20 log entries.
trace_service.sh Example:
#!/bin/bash
PID=$1
echo "PID: $PID"
# Extract service name managing this PID using systemd
# Hint: systemd can resolve a PID back to its unit
SERVICE=""
echo "SERVICE: $SERVICE"
echo "---- STATUS ----"
# Hint: show full systemd status for the identified service with --no-pager flag
echo "---- LOGS ----"
# Hint: show the last 20 log entries for the service from journald with --no-pager flag
Example
Running the script should produce a structured report similar to this:
root@server:~# ./trace_service.sh 4567
Service Identified: nginx.service
--- Status ---
β nginx.service - A high performance web server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled)
Active: active (running) since Fri 2025-12-19 14:00:00 UTC; 1h ago
Main PID: 4567 (nginx)
--- Last 20 Logs ---
Dec 19 14:00:01 server nginx[4567]: Starting web server...
Dec 19 14:00:02 server nginx[4567]: Configuration loaded successfully.
...
Terminal requires a larger screen
Open this page on a desktop or tablet (β₯ 768px) to launch the terminal and practice hands-on.
Linux Terminal Environment
Write and execute your solution in the terminal below.
Essential
Linux 0/29
AWS 0/10
Kubernetes 0/15
CI/CD 0/5
Networking 0/9
Need more practice in this area? Explore more questions β
NVIDIA
Accenture
Coinbase
Adobe
EPAM
Twitch
Amazon
Kayak
Autodesk
Lyft
Revolut
RedHat
Bloomberg
Datadog
Palantir
TCS
HashiCorp
Google
DeutscheBank
GitHub
Apple
Cloudflare
Stripe
Microsoft
GoDaddy
X
SAP
Spotify
Airbnb
Meta
Reddit
Yelp
Okta
Dropbox
Slack
ActivisionBlizzard
Zscaler
Uber
IBM
DeliveryHero
Robinhood
GitLab
Shopify
Samsung
Elastic
Twilio
Netflix
CrowdStrike
Ubisoft
Anthropic
Capital One
Splunk
Intel
AMD
Databricks