AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-500783

youni's questions

Martin Hope
youni
Asked: 2024-07-27 16:24:27 +0800 CST

如何删除 APT 中具有依赖关系的软件包?

  • 11

我希望保持系统清洁,并记录下已安装的软件包,以便以后可以删除它们。但有时依赖关系仍然存在。

我安装了该libasound2-plugin-equal包,它也拉进来了caps。我删除了libasound2-plugin-equal,但apt没有删除caps。

root@devuan:~# apt install libasound2-plugin-equal
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  caps
The following NEW packages will be installed:
  caps libasound2-plugin-equal
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 230 kB of archives.
After this operation, 632 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://deb.devuan.org/merged daedalus/main amd64 caps amd64 0.9.26-1 [215 kB]
Get:2 http://deb.devuan.org/merged daedalus/main amd64 libasound2-plugin-equal amd64 0.6-8 [14.9 kB]
Fetched 230 kB in 1s (211 kB/s)               
Selecting previously unselected package caps.
(Reading database ... 268554 files and directories currently installed.)
Preparing to unpack .../caps_0.9.26-1_amd64.deb ...
Unpacking caps (0.9.26-1) ...
Selecting previously unselected package libasound2-plugin-equal:amd64.
Preparing to unpack .../libasound2-plugin-equal_0.6-8_amd64.deb ...
Unpacking libasound2-plugin-equal:amd64 (0.6-8) ...
Setting up caps (0.9.26-1) ...
Setting up libasound2-plugin-equal:amd64 (0.6-8) ...
root@devuan:~# 
root@devuan:~# 
root@devuan:~# apt remove libasound2-plugin-equal
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be REMOVED:
  libasound2-plugin-equal
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 72.7 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 268570 files and directories currently installed.)
Removing libasound2-plugin-equal:amd64 (0.6-8) ...
root@devuan:~# 
root@devuan:~# 
root@devuan:~# apt autoremove
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
root@devuan:~# 

autoremove没有帮助。autoremove既然该caps包是作为依赖项安装的,为什么这里没有反应?

apt
  • 1 个回答
  • 274 Views
Martin Hope
youni
Asked: 2024-07-25 00:52:55 +0800 CST

如果我在后台运行进程,如何获取正在运行的 sh 脚本的 PID?

  • 5

我希望在后台进程中 ping 我的路由器。我还想将 ping 进程作为服务来控制:启动、状态、停止。因此,我创建了锁定文件并将 PID 存储在其中。但实际上 PID 正在发生变化,我无法终止进程。我将 PID 存储在变量 $$ 中,但它会发生变化,我不知道原因,可能是因为我运行了管道,也可能是我在后台运行进程?您能否告诉我,如何在 sh 脚本中获取 PID,我在后台运行管道的位置?

我的 sh 脚本 ping.sh 的代码:$ cat ping.sh

#!/bin/sh


option=$1

if [ "$option" = "start" ]; then
  if [ -f /tmp/ping.lock ]; then
    echo There is another ping process. Exit
    exit 1
  else
    touch /tmp/ping.lock
    (ping 192.168.1.1 | ts | tee -a >> ~/1) &
    echo $$ > /tmp/ping.lock ##here i store script pid
  fi

elif [ "$option" = "status" ]; then
  if [ -f /tmp/ping.lock ]; then
    echo ping is running. PID:
    cat /tmp/ping.lock
  else
    echo ping is not running
  fi

elif [ "$option" = "stop" ]; then
  if [ -f /tmp/ping.lock ]; then
    echo killing ping process
    kill $(cat /tmp/ping.lock)
    echo removing lock file
    rm /tmp/ping.lock
    echo ping stopped.
  else
    echo ping is not running.
  fi

else
  echo Usage: $0 [start, status, stop]
fi

实际上,该行echo $$ > /tmp/ping.lock ##here i store script pid并不存储实际的 PID,但存储的 PID 消失了。并且此调用不会终止我的脚本:

$ ./ping.sh 
Usage: ./ping.sh [start, status, stop]
$ ./ping.sh start
There is another ping process. Exit
$ rm /tmp/ping.lock 
$ 
$ ./ping.sh start
$ ps -ef | grep ping
y         5271  2221  1 19:36 ?        00:00:10 /usr/lib/chromium/chromium --show-component-extension-options --enable-gpu-rasterization --no-default-browser-check --disable-pings --media-router=0 --enable-remote-extensions --load-extension
y         5993  4075  0 19:44 pts/2    00:00:00 vim ping.sh
y         6089     1  0 19:45 pts/5    00:00:00 /bin/sh ./ping.sh start
y         6090  6089  0 19:45 pts/5    00:00:00 ping 192.168.1.1
y         6095  5241  0 19:45 pts/5    00:00:00 grep ping
$ 
$ cat /tmp/ping.lock 
6087
$ 
$ ./ping.sh stop
killing ping process
./ping.sh: 27: kill: No such process

removing lock file
ping stopped.
$ 
$ ps -ef | grep ping
y         5271  2221  1 19:36 ?        00:00:10 /usr/lib/chromium/chromium --show-component-extension-options --enable-gpu-rasterization --no-default-browser-check --disable-pings --media-router=0 --enable-remote-extensions --load-extension
y         5993  4075  0 19:44 pts/2    00:00:00 vim ping.sh
y         6089     1  0 19:45 pts/5    00:00:00 /bin/sh ./ping.sh start
y         6090  6089  0 19:45 pts/5    00:00:00 ping 192.168.1.1
y         6148  5241  0 19:46 pts/5    00:00:00 grep ping

可以看到,调用后./ping.sh stop我的脚本进程仍然存在,其 PID 为 6089,而锁文件中存储的 PID 为 6087。如何获取锁文件中存储的 PID 6089?何时以及如何存储它?

bash
  • 1 个回答
  • 33 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    模块 i915 可能缺少固件 /lib/firmware/i915/*

    • 3 个回答
  • Marko Smith

    无法获取 jessie backports 存储库

    • 4 个回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    user12345 无法获取 jessie backports 存储库 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl 为什么大多数 systemd 示例都包含 WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve