Linux process status file

How to see detailed information about a given PID?

The headline basically says it all. I have a program where I am only given the PID, nothing more really, and I would like to know how I get more information about the given process.

If you are working in python you probably want to use the psutil library. Do: psutil.Process(pid) to obtain the process object and then use its interface to retrieve information about memory/cpu etc. etc.

3 Answers 3

will show you some information. See the ps manpage for more information about the ps command. The «STANDARD FORMAT SPECIFIERS» section explains what the different columns mean.

I don’t know what is your exact requirement. but this may help you.

There is separate directory for every process with name as pid number in /proc .

ps -ef | grep docker root 1700 1 0 Sep20 ? 00:03:04 /usr/bin/docker daemon --raw-logs 

In above output PID is 1700 .

ls attr clear_refs cpuset fd limits mem net oom_score projid_map sessionid stat task autogroup cmdline cwd fdinfo loginuid mountinfo ns oom_score_adj root setgroups statm timers auxv comm environ gid_map map_files mounts numa_maps pagemap sched smaps status uid_map cgroup coredump_filter exe io maps mountstats oom_adj personality schedstat stack syscall wchan 

there is many file that have all information about process.

cat /proc/1700/status Name: docker State: S (sleeping) Tgid: 1700 Ngid: 0 Pid: 1700 PPid: 1 TracerPid: 0 Uid: 0 0 0 0 Gid: 0 0 0 0 FDSize: 64 Groups: 0 999 VmPeak: 527576 kB VmSize: 527512 kB VmLck: 0 kB VmPin: 0 kB VmHWM: 46032 kB VmRSS: 34180 kB VmData: 449308 kB VmStk: 136 kB VmExe: 28324 kB VmLib: 4236 kB VmPTE: 296 kB VmSwap: 5324 kB Threads: 12 SigQ: 0/63662 SigPnd: 0000000000000000 ShdPnd: 0000000000000000 SigBlk: 0000000000000000 SigIgn: 0000000000000000 SigCgt: ffffffffffc1feff CapInh: 0000000000000000 CapPrm: 0000003fffffffff CapEff: 0000003fffffffff CapBnd: 0000003fffffffff Seccomp: 0 Cpus_allowed: f Cpus_allowed_list: 0-3 Mems_allowed: 00000000,00000001 Mems_allowed_list: 0 voluntary_ctxt_switches: 437726 nonvoluntary_ctxt_switches: 27579 

If you need basic command to get process information then you can easily get using command:

Источник

Getting Linux process status from /proc

english

Linux /proc file system contains lots of information about the system and all running processes.
This article discusses one of the main files /proc//stat which gives information about current running process.
I could not find good documentation for this file.

This article is written after some search on the network and looking at the source.

Читайте также:  Линукс нано как сохранить

the stat file is an ascii file with one line of numbers and characters.
Fields are seperated with spaces.

The fields are as follows:
1. pid
2. Executable name (usually given in parathesis)
3. state (R — running, S — sleeping, D — uninterruptible wait, Z — zombie, T — traced or stopped)
4. effective user id
5. effective group id
6. Parrend pid
7. pgrp of the process
8. Session id of the process
9. tty used
10. tpgid (I could not find documentation for this field meaning)
11. flags of process (could not find documentation for flags meaning)
12. Number of minor faults
13. Number of minor faults with childs
14. Number of major faults
15. Number of major faults with childs
16. Usermode jiffies
17. Kernel mode jiffies
18. Usermode jiffies with childs
19. Kernel mode jiffies with childs
20. Process next timeslice
21. Standard nice value plus 15
22. Time in jiffies of next timeout
23. Time before next SIGALRM is sent
24. Time the process started after system bot
25. Virtual memory size
26. Resident set size
27. Current limit in bytes on resident set size
28. Start address of code
29. End address of code
30. Stack address
31. Value of ESP
32. Value of EIP
33. Bitmap of pending signals
34. Bitmap of blocked signals
35. Bitmap of ignomed signals
36. Bitmap of catched signals
37. Could not find documentation for this field
39. scheduler (Could not find documentation for meaning)
40. scheduler priority

Источник

Check if a Process Is Running in Linux

announcement - icon

The Kubernetes ecosystem is huge and quite complex, so it’s easy to forget about costs when trying out all of the exciting tools.

To avoid overspending on your Kubernetes cluster, definitely have a look at the free K8s cost monitoring tool from the automation platform CAST AI. You can view your costs in real time, allocate them, calculate burn rates for projects, spot anomalies or spikes, and get insightful reports you can share with your team.

Connect your cluster and start monitoring your K8s costs right away:

1. Overview

We usually have a lot of processes running on our machine. Some of them run for a very long time, while others only run briefly. And occasionally, we’ll need to monitor and control them. There are many commands available in the Linux ecosystem for managing them.

In this tutorial, we’ll see different approaches for checking if a process is running or not.

Читайте также:  Посмотреть работающие процессы linux

2. Setup

First, we’ll need a script that takes a long time to finish:

$ cat run.sh #!/bin/bash echo 'Starting. ' sleep 1000 echo 'Completed'

Then, we’ll start it in the background:

Next, let’s check the status of the script using different commands.

3. Using the ps Command

The ps command is one of the most commonly used Linux commands to monitor the process status.

It comes with various options to list the processes and their parameters. Consequently, this command provides us with detailed information regarding the processes:

$ ps -ef | grep run.sh bluelake 17838 2411 0 14:47 pts/0 00:00:00 /bin/bash ./run.sh bluelake 17842 2411 0 14:47 pts/0 00:00:00 grep --color=auto run.sh

Firstly, we’ve run the ps command and piped the result to the grep command. Secondly, in the grep command, we searched for the script name.

Let’s look at the different options we’ve used for the ps command:

  • -e: select all processes running in the system
  • -f: to view the full format listing of the process

Finally, we could see the script name in the result, which confirms that the script is indeed running. Typically, the ps command shows the PID (17838) and the parent PID (2411), as we can see here.

We could see one more process listed in the results. This is the grep command in the pipeline. By looking at it, we shouldn’t assume that the process is running as this will be always shown in the result.

4. Using the pgrep Command

Sometimes, we only need to check whether a process is active. We may not be interested in minute details regarding the process. For those situations, we can use the pgrep command.

Here’s the syntax of pgrep:

The pgrep command searches for the pattern among the currently running processes. And, once it finds a process it prints the PID and the process name depending upon the options we give while running the command.

Let’s see how we can use pgrep:

$ pgrep -l run.sh 18259 run.sh

Here, we can see it listed the running PID and its name. We’ve used the -l option to list the name of the process.

We may use other options as well:

  • -c: to get the count of processes
  • -f: to search in the full command including the arguments list
  • -a: to print the command line along with the PID
  • -i: to ignore case while searching
  • -x: list the process which exactly matches the pattern
  • -d: to set a different delimiter if we have more than one process (by default, a newline is used as a delimiter)
Читайте также:  Google drive linux client

5. Using the pidof Command

The pidof command finds and prints the PID of a process. It’s similar to the pgrep command we saw above.

Let’s see the syntax of pidof:

pidof [-s] [-c] [-q] [-w] [-x] [-o omitpid[,omitpid. ]. ] [-S separator] program [program. ]

We’ve run the pidof command with the -x option to include any running scripts in the search. And it has listed the PID of the script we started.

In this command, we can give more than one process name or script name to search for. It prints the PIDs in a single line. As a result, we can then pipe these resulting PIDs into another command to perform additional operations on the PIDs found.

6. Using the proc File System

The proc file system is another place where we can find the information related to different processes in our system. We can find it in most of the Linux distributions out there. Therefore, this method of finding information related to the process is intended to work in the majority of situations.

The proc file system stores the kernel information. It stores the live system data organized in different files and folders. We can look into those files for specific information.

Apart from other files, this file system has a directory named after the PID for each process. Inside that directory, we can find a lot of files containing the metadata related to that process. Out of those, we can find a status file that contains basic process information in a human-readable format.

The idea here is to grep through this file in all these PID subdirectories:

$ grep "run.sh" /proc/4*/status | awk -F: '' 19071 run.sh

Here, we’ve used the grep command to search in the PID subdirectories for the process name. Then, the results, which contain the file path and process name, are piped to the awk command. From the file path, we extract the PID using the split function. Finally, we print the PID and process name.

7. Conclusion

In this article, we saw different ways to check if a process is running.

We’ve seen that the pgrep and the pidof commands show minimal information about the processes.

On the other hand, the ps command displays more information. Furthermore, if we need a deeper understanding we can use the proc file system.

Источник

Оцените статью
Adblock
detector