Pgrep
pgrep là một phần mềm tiện ích Unix, ban đầu được viết cho Solaris 7, sau đó được tích hợp vào bộ phần mềm procps-ng trên hệ điều hành GNU/Linux, các hệ điều hành BSD và một số hệ điều hành giống Unix khác. Lệnh pgrep tìm kiếm tất cả những tiến trình có tên phù hợp với biểu thức chính quy được đưa ra, và mặc định trả về ID của tiến trình. Các lệnh tương tự bao gồm pidof (tìm ID tiến trình theo tên chương trình) hay ps.
Ví dụ
pgrep làm đơn giản hóa câu lệnh tìm kiếm tiến trình:
pgrep 'sh'
Tương đương với:
ps ax | awk '/[p]rocessname/ {print $1}'
hay nếu dùng grep:
ps ax | grep 'processname' | grep 'grep' -v | awk '{print $1}'
Một chức năng khác của pgrep là hiển thị tên và PID của tất cả tiến trình thuộc một nhóm:
pgrep -l -G users
Lệnh trên hiển thị tất cả các tiến trình thuộc về nhóm users, tuy nhiên tùy chọn -G cũng có thể nhận cả ID.
pgrep -v -u foo
Lệnh trên hiển thị tất cả các tiến trình trừ các tiến trình của người dùng foo. Hiển thị ID tiến trình được bắt đầu gần nhất:
pgrep -n
Hiển thị tiến trình ls gần nhất được người dùng foo bắt đầu:
pgrep -n -l -u foo ls
Xem thêm
- pidof — tìm process ID của chương trình đang chạy
- pkill — gửi tín hiệu tới tiến trình dựa theo tên và các thuộc tính khác
- ps — hiển thị những tiến trình đang chạy
- grep — tìm những dòng văn bản phù hợp với một hoặc vài biểu thức chính quy
Tham khảo
Liên kết ngoài
- FreeBSD pgrep(1) manpage
- Solaris pgrep(1) manpage
- procps-ng pgrep(1) manpage
- A Comparison of Unix® pgrep Implementations Lưu trữ ngày 28 tháng 1 năm 2015 tại Wayback Machine
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.