Command Management Process and Thread in UBUNTU
Tags: serverless, ubuntu, os, systems
Published: 2023-03-17 02:52:31

## Managing service
`service <service_name> <action>`
```
Example:
service sshd status
```
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fc9dc0pobnxlkmxhu2tu.png)
```
service sshd start
```
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gdvpx30vwdjzyhxgrnx5.png)
```
service sshd stop
```
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jkujj5b3znl349sym5kt.png)

Where <service_name> is the name of the system service you want to manage, and <action> is the action you want to perform on the service (such as start, stop, restart, enable, or disable).

In addition to the basic syntax, the service command also supports several attributes or options that can be used to customize its behavior. Some of the most commonly used attributes include:

- status-all: This attribute displays the status of all system services, whether they are currently running or not.
- reload: This attribute reloads the configuration file for a service without actually stopping and restarting the service.
- full-restart: This attribute performs a full restart of a service, which involves stopping and then starting the service again.
- list: This attribute lists all available system services that can be managed with the service command.

## Running Init

`/etc/init.d/[servie] [command]`
the /etc/init.d command in Linux is a directory containing scripts used to start, stop, and restart system services on the system. These scripts can be run directly using specific arguments, or using the service command, which provides a simpler interface for managing system services.
```
Example:
/etc/init.d/ssh start
/etc/init.d/ssh stop
/etc/init.d/ssh restart
/etc/init.d/ssh status
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hw87t4xiokndzbj0ux27.png)

## Top
``top``
The purpose of the top command is to provide an easy-to-use interface for monitoring and managing running processes on a Linux system. It can be used to identify resource-intensive processes, find out which processes are consuming the most system resources, and terminate or suspend processes as needed.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4f460y3r2lbqu8n744o2.png)

####description of each column in the table output:

- PID: The process ID of the task.
- USER: The user who started the process.
- PR: The priority of the process.
- NI: The "nice" value of the process, which determines its priority in the scheduling queue.
- VIRT: The total amount of virtual memory used by the process.
- RES: The amount of physical memory used by the process.
- SHR: The amount of shared memory used by the process.
- S: The process state. It can be R (running), S (sleeping), D (disk sleep), Z (zombie), or T (stopped).
- %CPU: The percentage of CPU time used by the process since the last update.
- %MEM: The percentage of physical memory used by the process.
- TIME+: The total CPU time used by the process since it started.
- COMMAND: The command that started the process.

### Some of the key attributes of the top command include:

1. Process List: The main display of the top command is a list of all the processes running on the system, along with detailed information about each process, such as the process ID (PID), user, CPU usage, memory usage, and more.

2. Resource Consumption: The top command provides real-time information about the system's resource usage, including CPU usage, memory usage, and system uptime. This information is displayed both as overall statistics for the entire system and as individual statistics for each process.

3. Sorting Options: The top command allows users to sort the process list based on a variety of criteria, such as CPU usage, memory usage, process ID, and more. This makes it easy to identify resource-intensive processes and take action as needed.
4. Interactive Features: The top command is an interactive tool that allows users to manipulate the process list in real-time. For example, users can suspend or resume processes, change the priority of running processes, and more.