一个 screen 简单教程(from CU)

本文介绍Screen终端管理器的基本使用方法,包括启动、窗口管理、屏幕输出记录等实用技巧。
部署运行你感兴趣的模型镜像
 原贴:http://blog.chinaunix.net/u/13548/showart_489435.html

一个 screen 简单教程
发信人: Dieken (风催草低 - 明月何尝不照人), 信区: LinuxApp
标 题: 又一个 screen 简单教程
发信站: 水木社区 (Tue Mar 4 14:05:05 2008), 站内

又一个 screen 简单教程
======================


screen 是一个特殊的模拟终端软件,利用它能在一个终端窗口里模拟出多个终端,
并且能分割窗口、类似 VI 的方式搜索和拷贝屏幕输出,最重要的是利用
screen,可以让任务后台执行,退出系统,下次登录恢复后跟以前状态一样。


1) 运行

执行 screen 命令就是新开一个 screen 会话,其它常用命令:

列举当前存在的 screen 会话
$ screen -ls
[2]dieken@tsg:~$ screen -ls
There is a screen on:
12212.pts-24.tsg (Detached)
1 Socket in /var/run/screen/S-dieken.

括号中的 Detached 表示这个会话在后台运行,用 screen -R 恢复它。
如果有多个 Detached 的会话,则用 screen -R 12212 恢复它;如果突然
掉线导致那个会话还处于 Attached 状态,则用 screen -dR 12212 恢复。


2) 退出
screen 内会执行 shell,退出所有 shell 后 screen 就退出了,或者
在 screen 里头按 Ctrl-a d 来 detach 这个 screen 会话,以后就能
用 screen -R 恢复这个会话。


3) 帮助:
Ctrl-a ? 或者 man screen


4) 窗口操作:
Ctrl-a c 开新窗口(退出里头的 shell 比如用 exit 或者 ctrl-d 则退出此窗口)
Ctrl-a Ctrl-a 切换窗口
Ctrl-a 0 到 9 直接切换到某个窗口,窗口编号能用 Ctrl-a " 看到,这个命令
会列出所有窗口,按上下方向键或者类似 vi 的 hj,高亮然后回车选择


5) 窗口分割,可以利用这个功能一边编辑一边查看编译结果。
Ctrl-a S 分割窗口
Ctrl-a j 切换到下一个窗口
Ctrl-a k 切换到上一个窗口
Ctrl-a b 切换到最底下的窗口
Ctrl-a t 切换到最顶上的窗口
然后用 4 中的切换操作让新分割出来的窗口显示内容

Ctrl-a X 关闭当前窗口(关闭的只是分割出来的窗口,并不是 4 中新建的窗口)


6) 记录屏幕输出
Ctrl-a H 类似 script 程序,记录屏幕上显示的内容,再按此快捷键停止记录。


7) 回滚、搜索、拷贝屏幕输出
Ctrl-a ESC 或者 Ctrl-a [ 进入回滚、拷贝模式

进去此模式后就可以用 vi 的命令移动光标:h, j, k, l, 0, ^, $, H, M, L,
G, |, w, b, e, B, E, Ctrl-u, Ctrl-d, Ctrl-b, Ctrl-f, g, %

拷贝:在起始点和终点各按一次空格键,这就拷贝了高亮文字并退出回滚、拷贝
模式,进入正常模式,用 Ctrl-a ] 就可以粘贴。

搜索:类似 vi 的 / 和 ? 命令,或者 Emacs 的 C-a s 和 C-r 命令


8) 锁住 screen
Ctrl-a x 需要输入密码才能继续使用


9) 配置,screen 默认用 Ctrl-a 作为快捷键前缀,这跟命令行编辑的 Ctrl-a 跳到
行首冲突,因此可以在 ~/.screenrc 里配置为 Ctrl-j:
defescape ^Jj
escape ^Jj

建议在 ~/.bashrc 中设置 PS1 的后面一行加入
PS1="//n[/$SHLVL]$PS1"
这句,这样能容易看出当前的 shell 是否嵌套在其它 shell 里运行的。


我的配置文件,从 jetspeed 的抄的,有两行太长了所以加了行号,使用的
时候记得去掉:

1 vbell off
2 defescape ^Jj
3 escape ^Jj
4
5 startup_message off
6
7 # define a bigger scrollback, default is 100 lines, I like large
scrollback
8 defscrollback 2048
9
10 # An alternative hardstatus to display a bar at the bottom listing the
11 # windownames and highlighting the current windowname in blue. (This is
only
12 # enabled if there is no hardstatus setting for your terminal)
13 hardstatus on
14 hardstatus alwayslastline
15 hardstatus string "%{.bW}%-w%{.rW}%n %t%{-}%+w %=%{..G} %H %{..Y} %m/%d
%C%a "
16
17 # another way to show window list
18 #caption always "%?%F%{-b 4w}%:%{-b bb}%? %H | %l | %m-%d %c |%?%F%{-b
4w}%?%L=%-Lw%45>%{-b w4}%n%f* %t%{-}%+Lw%-0<"
19
20 # key bingdings
21 # remove some stupid/dangerous key bindings
22 bind k
23 bind ^k
24 bind .
25 bind ^/
26 bind //
27 bind ^h
28 bind h
29 bind l windowlist
30 bindkey ^[, prev
31 bindkey ^[. next
32
33 # some useful keys for resizing
34 bind = resize =
35 bind + resize +1
36 bind - resize -1
37 bind _ resize max
38
39 # bind some keys for moving between split windows
40 bind j focus down
41 bind k focus up
42 bind t focus top
43 bind b focus bottom
44





--
On Sat, 22 Sep 2007, Dmitry Kakurin wrote:
> We've had this theoretical (and IMHO pointless) discussion C vs. C++ *in
> general*.

I think "pointless" is more to the point.
We don't want C++. Why is that so hard to accept?
Re: C++ *for Git* Johannes Schindelin
http://thread.gmane.org/gmane.comp.version-control.git/58929/focus=58933


※ 来源:·水木社区 newsmth.net·[FROM: 211.157.41.*]

您可能感兴趣的与本文相关的镜像

Stable-Diffusion-3.5

Stable-Diffusion-3.5

图片生成
Stable-Diffusion

Stable Diffusion 3.5 (SD 3.5) 是由 Stability AI 推出的新一代文本到图像生成模型,相比 3.0 版本,它提升了图像质量、运行速度和硬件效率

C01120/foundation/BMS: caller not shell 11-19 08:10:14.284 1590 58510 I C05A01/foundation/ATM: [GetKernelPermissions:782]TokenID=537231906. 11-19 08:10:14.285 3049 3049 I A01A00/com.ohos.sceneboard/SYS_UI: StatusBarBackground: aboutToAppear StatusBarBackground 11-19 08:10:14.285 1590 58510 I C01311/foundation/AppMS: [AMSI4249]apl: normal, com.huawei.hmos.screenrecorder, startFlags: 2048, u: 100 11-19 08:10:14.285 1590 58510 I C01300/foundation/AAFwk: [task_handler_wrap56]Invalid status 11-19 08:10:14.285 1590 58510 I C02C11/foundation/APPSPAWN_CLIENT: [appspawn_client.c:436]AppSpawnClientSendMsg reqId: 6315 msgLen: 2020 fd: 121 com.huawei.hmos.screenrecorder 11-19 08:10:14.285 589 589 I C02C11/appspawn/APPSPAWN: [appspawn_service.c:442]connectionId:2 buffLen:2020 11-19 08:10:14.285 589 589 I C02C11/appspawn/APPSPAWN: [appspawn_service.c:1780]Recv message header magic 0xef201234 type 0 id 6261 len 2020 com.huawei.hmos.screenrecorder 11-19 08:10:14.285 589 589 W C02C11/appspawn/APPSPAWN: [sandbox_shared_mount.cpp:199]umount2 /mnt/sandbox/100/com.huawei.hmos.screenrecorder/data/storage/el1/bundle failed, errno 22 11-19 08:10:14.285 589 589 I C02C11/appspawn/APPSPAWN: mount path /mnt/sandbox/100/com.huawei.hmos.screenrecorder/data/storage/el1/bundle to shared success 11-19 08:10:14.285 589 589 I C02C11/appspawn/APPSPAWN: lockStatus 100 0 11-19 08:10:14.285 589 589 I C02C11/appspawn/APPSPAWN: AppSpawn msgId:6261 msgLen:2020 tlvCount:6 processName:com.huawei.hmos.screenrecorder 11-19 08:10:14.285 589 589 I C02C11/appspawn/APPSPAWN: com.huawei.hmos.screenrecorder 0 App flags:0x800 11-19 08:10:14.285 589 589 I C02C11/appspawn/APPSPAWN: com.huawei.hmos.screenrecorder 1 App flags:0x4 11-19 08:10:14.285 589 589 I C02C11/appspawn/APPSPAWN: com.huawei.hmos.screenrecorder 0 App permission bits flags:0x0 11-19 08:10:14.285 589 589 I C02C11/appspawn/APPSPAWN: com.huawei.hmos.screenrecorder 1 App permission bits flags:0x0 11-19 08:10:14.285 589 589 I C02C11/appspawn/APPSPAWN: uid:20020157 gid:20020157 count:1 11-19 08:10:14.285 589 589 I C02C11/appspawn/APPSPAWN: App BundleName:com.huawei.hmos.screenrecorder index:0 11-19 08:10:14.285 589 589 I C02C11/appspawn/APPSPAWN: apl:normal 0x1 11-19 08:10:14.286 3049 3049 I C03942/com.ohos.sceneboard/AceTextClock: [(100000:100000:scope)] Clock is visible and clock starts running 11-19 08:10:14.286 3049 3049 I C03942/com.ohos.sceneboard/AceTextClock: [(100000:100000:scope)] Clock is visible and clock starts running 11-19 08:10:14.286 58527 58527 I C02C11/appspawn/APPSPAWN: AppSpawnChild id 6260 flags:0x8 11-19 08:10:14.286 58527 58527 I C02C02/PARAM: [param_request.c:326]ResetParamSecurityLabel Fd:19 11-19 08:10:14.287 58527 58527 I C02D33/com.huawei.hmos.screenrecorder/HitraceOption: FilterAppTrace com.huawei.hmos.screenrecorder 58527 11-19 08:10:14.287 3049 3049 I A01A00/com.ohos.sceneboard/SYS_UI: GroupBackgroundEffect --> aboutToAppear GroupBackgroundEffect left_group 11-19 08:10:14.288 3049 3049 I A01A00/com.ohos.sceneboard/SYS_UI: GroupBackgroundEffect --> LightNess: 100 colorStr: #FFFFFFFF 11-19 08:10:14.288 3049 3049 I A01A00/com.ohos.sceneboard/SYS_UI: StatusBarHeightVm: preSetShowHeight setName: GroupBackgroundEffect newHeight: 58 changeHotArea: false 11-19 08:10:14.288 3049 3049 I A01A00/com.ohos.sceneboard/SYS_UI: StatusBarHeightVm: checkHeightChange: cacheUseHeight 58 maxHeight 58 maxHotArea: 39 11-19 08:10:14.289 3049 3049 I A01A00/com.ohos.sceneboard/SYS_UI: StatusBarBridgeView: change bar statusBarType: from 2 to 2 11-19 08:10:14.289 3049 3049 I C03F01/com.ohos.sceneboard/NAPI: taskpool:: Task PerformTask End: 2382625920 11-19 08:10:14.289 3049 58473 I C02B61/com.ohos.sceneboard/ImageCode: ImageSource::UpdateXmageCoordinatesFromExif cost 15 us 11-19 08:10:14.289 3049 3049 I A01B00/com.ohos.sceneboard/SCB: TaskpoolUtil: task sequenceExecute 11-19 08:10:14.289 3049 3049 I A01B00/com.ohos.sceneboard/SCB: TaskpoolUtil: task sequenceExecute finally 11-19 08:10:14.290 3049 3049 I A01B04/com.ohos.sceneboard/CC: Ctrl.IOTMainPage: error get iotRoot 100001 11-19 08:10:14.291 3049 58473 I C02B61/com.ohos.sceneboard/ImageSource: CreatePixelMap success, id:1763511014289715,dSize:560,232,sSize:560,232,dHdr:1,sHdr:1,memType:2,cost 1335 us 11-19 08:10:14.292 6033 22122 W C01401/anco_service_broker/Bufferqueue: <buffer_utils.cpp:141-ReadSurfaceBufferImpl>: sequence is invalid: 395421001 11-19 08:10:14.292 6033 22122 W C01401/anco_service_broker/Bufferqueue: <surface_buffer_impl.cpp:182-SurfaceBufferImpl>: SurfaceBufferImpl error, sequence is exist, seq: 395421001 11-19 08:10:14.293 3049 3049 I C03942/com.ohos.sceneboard/AceTextClock: [(100000:100000:scope)] Clock is in the visible area and clock starts running 11-19 08:10:14.293 3049 3049 I C03942/com.ohos.sceneboard/AceTextClock: [(100000:100000:scope)] Clock is in the visible area and clock starts running 11-19 08:10:14.300 58527 58527 I C02C11/com.huawei.hmos.screenrecorder/APPSPAWN: errno:2 bind mount /system/data to /mnt/sandbox/100/com.huawei.hmos.screenrecorder/system/data 11-19 08:10:14.301 58527 58527 I C02C11/com.huawei.hmos.screenrecorder/APPSPAWN: file /mnt/sandbox/100/com.huawei.hmos.screenrecorder/data/service/el1/public/hosts_user/hosts already exist 11-19 08:10:14.301 58527 58527 I C02C11/com.huawei.hmos.screenrecorder/APPSPAWN: errno:2 bind mount /system/etc/hosts to /mnt/sandbox/100/com.huawei.hmos.screenrecorder/data/service/el1/public/hosts_user/hosts 11-19 08:10:14.301 58527 58527 I C02C11/com.huawei.hmos.screenrecorder/APPSPAWN: errno:2 bind mount /vendor/lib to /mnt/sandbox/100/com.huawei.hmos.screenrecorder/vendor/lib 11-19 08:10:14.305 58527 58527 I C02C11/com.huawei.hmos.screenrecorder/APPSPAWN: errno:2 bind mount /data/app/el1/public/aot_compiler/ark_cache/com.huawei.hmos.screenrecorder to /mnt/sandbox/100/com.huawei.hmos.screenrecorder/data/storage/ark-cache 11-19 08:10:14.305 58527 58527 I C02C11/com.huawei.hmos.screenrecorder/APPSPAWN: check dir /data/app/el1/public/aot_compiler/ark_cache/com.huawei.hmos.screenrecorder failed,strerror:No such file or directory 11-19 08:10:14.306 58527 58527 I C02C11/com.huawei.hmos.screenrecorder/APPSPAWN: errno:13 private mount to /mnt/sandbox/100/com.huawei.hmos.screenrecorder/data/service/el0/public/for-all-app '524288' failed 11-19 08:10:14.306 6033 22122 W C01401/anco_service_broker/Bufferqueue: <buffer_utils.cpp:141-ReadSurfaceBufferImpl>: sequence is invalid: 395421005 11-19 08:10:14.306 6033 22122 W C01401/anco_service_broker/Bufferqueue: <surface_buffer_impl.cpp:182-SurfaceBufferImpl>: SurfaceBufferImpl error, sequence is exist, seq: 395421005 11-19 08:10:14.308 58527 58527 I C02C11/com.huawei.hmos.screenrecorder/APPSPAWN: errno:2 bind mount /chip_prod/etc/passthrough to /mnt/sandbox/100/com.huawei.hmos.screenrecorder/chip_prod/etc/passthrough 11-19 08:10:14.309 58527 58527 I C02C11/com.huawei.hmos.screenrecorder/APPSPAWN: errno:13 private mount to /mnt/sandbox/100/com.huawei.hmos.screenrecorder/vendor/etc/vulkan '524288' failed 11-19 08:10:14.310 58527 58527 I C02C11/com.huawei.hmos.screenrecorder/APPSPAWN: errno:2 bind mount /vendor/etc/silk to /mnt/sandbox/100/com.huawei.hmos.screenrecorder/vendor/etc/silk 11-19 08:10:14.310 58527 58527 I C02C11/com.huawei.hmos.screenrecorder/APPSPAWN: errno:2 bind mount /system/asan/lib64 to /mnt/sandbox/100/com.huawei.hmos.screenrecorder/system/asan/lib64 11-19 08:10:14.310 58527 58527 I C02C11/com.huawei.hmos.screenrecorder/APPSPAWN: errno:2 bind mount /vendor/asan/lib64 to /mnt/sandbox/100/com.huawei.hmos.screenrecorder/vendor/asan/lib64 11-19 08:10:14.310 58527 58527 I C02C11/com.huawei.hmos.screenrecorder/APPSPAWN: errno:13 private mount to /mnt/sandbox/100/com.huawei.hmos.screenrecorder/chip_prod/lib64/passthrough '524288' failed 11-19 08:10:14.311 58527 58527 I C02C11/com.huawei.hmos.screenrecorder/APPSPAWN: errno:2 bind mount /system/app/ohos.global.systemres to /mnt/sandbox/100/com.huawei.hmos.screenrecorder/data/global/systemResources 11-19 08:10:14.312 58527 58527 I C02C11/com.huawei.hmos.screenrecorder/APPSPAWN: errno:2 bind mount /data/preload/app to /mnt/sandbox/100/com.huawei.hmos.screenrecorder/data/preload/app 11-19 08:10:14.316 58527 58527 I C02C11/com.huawei.hmos.screenrecorder/APPSPAWN: path /storage/Users/currentUser/Download/com.huawei.hmos.screenrecorder mode 0x3 11-19 08:10:14.316 58527 58527 E C05A06/com.huawei.hmos.screenrecorder/CODE_SIGN: [XpmIoctl]:Ioctl cmd 40087803 failed: Invalid argument (ignore) 11-19 08:10:14.317 58527 58527 E C05A03/com.huawei.hmos.screenrecorder/Selinux: Read /version/etc/selinux/product_config failed, errno: No such file or directory 11-19 08:10:14.321 58527 58527 I C05A05/com.huawei.hmos.screenrecorder/SecCompEnhanceClient: [RegisterCheckCallback]Register secComp: sessionId=4060566908, seqNum=******018. 11-19 08:10:14.323 968 968 I C05A01/accesstoken_service/ATM: [RegisterSecCompEnhance:1695]Pid: 0 11-19 08:10:14.323 968 968 I C05A01/accesstoken_service/ATM: [RegisterSecCompEnhance:123]Register sec comp enhance success, pid 58527, total 57. 11-19 08:10:14.323 58527 58527 I C02D0B/com.huawei.hmos.screenrecorder/HICHECKER: hichecker param is empty. 11-19 08:10:14.323 58527 58527 I C04500/com.huawei.hmos.screenrecorder/webview: SelectWebcoreBeforeProcessRun: SelectWebcoreBeforeProcessRun for app com.huawei.hmos.screenrecorder. 11-19 08:10:14.323 58527 58527 I C02C11/com.huawei.hmos.screenrecorder/APPSPAWN: ClearEnvAndReturnSuccess 4 11-19 08:10:14.323 58527 58527 I C01317/com.huawei.hmos.screenrecorder/AppKit: [MAINTHD3020]mainthread start, pid:58527 11-19 08:10:14.323 589 589 I C02C11/appspawn/APPSPAWN: [appspawn_service.c:1053]Child process com.huawei.hmos.screenrecorder success pid 58527 appId: 6260 result: 0 11-19 08:10:14.323 589 589 I C02C11/appspawn/APPSPAWN: [appspawn_appmgr.c:169]Add com.huawei.hmos.screenrecorder, pid=58527 success 11-19 08:10:14.323 589 589 I C02C11/appspawn/APPSPAWN: [appspawn_service.c:602]watch app process pid 58527, pidFd 82 11-19 08:10:14.324 589 589 I C02C11/appspawn/APPSPAWN: [appspawn_service.c:266]SendMessageComplete connectionId: 2 result 0 app com.huawei.hmos.screenrecorder pid 58527 11-19 08:10:14.324 1590 58510 I C02C11/foundation/APPSPAWN_CLIENT: [appspawn_client.c:444]AppSpawnClientSendMsg reqId: 6315 fd: 121 end result: 0x0 pid: 58527 11-19 08:10:14.324 1590 58510 I C01311/foundation/AppMS: [ASC633]pid58527 11-19 08:10:14.324 1590 58510 I C01311/foundation/AppMS: [AMSI4472]spawned pname: com.huawei.hmos.screenrecorder pid: 58527 11-19 08:10:14.324 1707 1914 I C02B91/av_session/AVSession: [HandleAppStateChanged]uid=20020157|pid=58527|state=0 11-19 08:10:14.324 754 47091 I C02B87/audio_server/AudioServiceAppStateListener: [OnAppStateChanged]app state changed, bundleName=com.huawei.hmos.screenrecorder uid=20020157 pid=58527 state=0 11-19 08:10:14.325 1590 58510 W C01336/foundation/AMS: [resident_process_manager269]rdbResult: 5 11-19 08:10:14.325 754 47091 W C02B8B/audio_server/DfxMsgManager: [CheckCanAddAppInfo]skip system app dfx msg.., appuid=20020157 11-19 08:10:14.325 58527 58527 I C01317/com.huawei.hmos.screenrecorder/AppKit: [MAINTHD416]attach 11-19 08:10:14.326 1590 58510 I C01311/foundation/AppMS: [AMSI1461]attach com.huawei.hmos.screenrecorder pid:58527 11-19 08:10:14.326 1590 58510 I C01311/foundation/AppMS: [ARR538]Launch pending abilities. 11-19 08:10:14.327 904 58432 I C0470A/resource_schedule_service/GameServicePerf: [a92abb0ae64fba7 0 0][(DispatchResource:233)]GameServiceScenePlugin recv event: type=1 value=0 payload=<private> 11-19 08:10:14.327 754 47091 I C02B87/audio_server/AudioServiceAppStateListener: [OnAppStateChanged]app state changed, bundleName=com.huawei.hmos.screenrecorder uid=20020157 pid=58527 state=99 11-19 08:10:14.327 1707 1914 I C02B91/av_session/AVSession: [HandleAppStateChanged]uid=20020157|pid=58527|state=99 11-19 08:10:14.327 1590 58495 I C01311/foundation/AppMS: [ASOM649]b:com.huawei.hmos.screenrecorder pid:58527 u:20020157 pt:1 et:3 pName:com.huawei.hmos.screenrecorder ru:-1 tMode:0 cPid:3049 cU:20020018 11-19 08:10:14.327 904 58489 I C01735/resource_schedule_service/LOWPOWER_MANAGER: [a92abb0ae64fba7 0 0][IsContainerFrontApp:496] anco app is visible 11-19 08:10:14.327 904 58436 I C0470A/resource_schedule_service/GameServicePerf: [a92abc0ae650016 0 0][(DispatchResource:233)]GameServiceScenePlugin recv event: type=4 value=0 payload=<private> 11-19 08:10:14.327 904 58436 I C01702/resource_schedule_service/CgroupEventHandler: [a92abc0ae650016 0 0]HandleProcessCreated : 20020157, 58527, 0, 1, com.huawei.hmos.screenrecorder, 3 11-19 08:10:14.327 904 58436 I C01702/resource_schedule_service/CgroupAdjuster: [a92abc0ae650016 0 0]AdjustProcessGroup for 58527, source : 3 11-19 08:10:14.328 904 58433 I C01703/resource_schedule_service/socperf: [a92abc0ae650016 0 0][HandleProcessStateChange]: SocPerfPluginExt::ProcessStateChange value=0 type=1 pid=58527 11-19 08:10:14.328 904 58378 I C01731/resource_schedule_service/SUSPEND_MSG: [a92abc0ae650016 0 0]20020157_com.huawei.hmos.screenrecorder_58527 create, type:1_3_0 11-19 08:10:14.328 904 58434 I C01702/resource_schedule_service/CgroupAdjuster: [a92abc0ae650016 0 0]ApplyProcessGroup Set 58527's cgroup from 255 to 0. 11-19 08:10:14.328 904 6040 I C01735/resource_schedule_service/LOWPOWER_MANAGER: [a92abb0ae64fba7 0 0][ProcessEvent:36] event 1 process 11-19 08:10:14.328 771 771 I C01707/concurrent_task_service/CONCUR: [a92abb0ae64fba7 0 0][ProcMgr] app 58527 start, 2AAA size()=52 11-19 08:10:14.328 904 1156 I C01718/resource_schedule_service/StandbyService: [OnProcessStatusChanged:922] process status change, uid: 20020157, pid: 58527, name: com.huawei.hmos.screenrecorder, alive: 1 11-19 08:10:14.328 904 58376 I C01704/resource_schedule_service/TagSched: [a92abc0ae650016 0 0][SetQosRealtimeTask]ThreadModifyQos,setQos 58527 tid[58527], qos[7] 11-19 08:10:14.329 904 58379 I C01705/resource_schedule_service/IOLIMIT: [a92abc0ae650016 0 0][(CheckIsRemoveAndSystem):399] com.huawei.hmos.screenrecorder is system app 11-19 08:10:14.330 904 1166 I C01713/resource_schedule_service/SUSPEND_MANAGER: [a92abc0ae650016 0 0]add freeze unit: 20020157_com.huawei.hmos.screenrecorder, C_[(0,0,0,0,1)], T_0, R_0, S_0, pT_0, eT_3, cC_0, [58527_0_0][] 11-19 08:10:14.330 904 1166 I C01731/resource_schedule_service/SUSPEND_MSG: [a92abc0ae650016 0 0]pid:58527, detectStatus:1, timeoutDuration:11000 11-19 08:10:14.330 6033 22122 W C01401/anco_service_broker/Bufferqueue: <buffer_utils.cpp:141-ReadSurfaceBufferImpl>: sequence is invalid: 395421002 11-19 08:10:14.330 6033 22122 W C01401/anco_service_broker/Bufferqueue: <surface_buffer_impl.cpp:182-SurfaceBufferImpl>: SurfaceBufferImpl error, sequence is exist, seq: 395421002 11-19 08:10:14.331 58527 58527 E C01317/com.huawei.hmos.screenrecorder/AppKit: [MAINTHD3855]developer Mode false 11-19 08:10:14.331 58527 58619 I C01317/com.huawei.hmos.screenrecorder/AppKit: [MAINTHD810]ScheduleLaunchAbility called, ability com.huawei.hmos.screenrecorder.ServiceExtAbility, type is 5. 11-19 08:10:14.331 838 56758 I C02699/memmgrservice/MM: OnProcessCreated 20020157,58527,com.huawei.hmos.screenrecorder,com.huawei.hmos.screenrecorder,0,0,1,0 11-19 08:10:14.331 838 58427 I C02699/memmgrservice/MM: UpdatePriorityLocked CRE: 58527, 20020157, 200, [], 00000 11-19 08:10:14.332 974 58419 I C015B5/netmanager/NetMgrEnhanced: OnAppStarted appName:com.huawei.hmos.screenrecorder uid:20020157 pid:58527 state:0 11-19 08:10:14.332 974 58419 I C015B5/netmanager/NetMgrEnhanced: NotifyAbilityStateChanged:uid=2******7, pid=58527, state=0, abilityName=com.huawei.hmos.screenrecorder.ServiceExtAbility 11-19 08:10:14.333 3049 3049 I A01A00/com.ohos.sceneboard/SYS_UI: AppLifeCycleManager: StateChanged, state is not page com.huawei.hmos.screenrecorder_phone_com.huawei.hmos.screenrecorder.ServiceExtAbility_58527 11-19 08:10:14.334 58527 58527 I C03900/com.huawei.hmos.screenrecorder/ACE_UIContent: [69]AceForwardCompatibility [com.huawei.hmos.screenrecorder] force:1 newpipe:1
最新发布
11-27
<think> 我们正在处理一个日志错误:"C01120/foundation/BMS: caller not shell"。这个错误发生在BMS(Bundle Manager Service)中,提示调用者不是shell用户。在Android系统中,BMS负责管理应用程序包(APK)的安装、更新和卸载等操作。某些操作需要特定的权限,特别是当涉及到系统级别的操作时,通常要求调用者是shell用户(即具有root权限或通过adb shell执行)。 ### 错误原因分析: 1. **权限不足**:该错误通常表示当前执行操作的进程或命令没有以shell用户身份运行。在Android系统中,许多系统级操作(如包管理、设备配置等)需要shell权限(通常是`shell`或`root`用户组)。 2. **调用上下文错误**:可能是在非shell环境(如普通应用进程)中尝试执行了只能由shell用户执行的操作。例如,通过`pm`(Package Manager)命令安装或卸载应用,必须通过adb shell执行。 3. **错误的UID(用户ID)**:BMS在检查调用者的UID时,发现其不是`SHELL_UID`(通常为2000),因此拒绝执行操作。 ### 解决方案: #### 1. **确保以shell用户身份执行操作** - 通过ADB连接设备,并使用`adb shell`命令进入shell环境后再执行相关操作。 ```bash adb shell pm install /path/to/your.apk # 在shell中执行 ``` #### 2. **检查调用者的权限** - 如果是在应用程序中调用,确保应用具有`android.permission.INSTALL_PACKAGES`权限(该权限通常只授予系统应用)。 - 在`AndroidManifest.xml`中声明权限(但普通应用无法获得此权限,只有系统应用或签名应用可以): ```xml <uses-permission android:name="android.permission.INSTALL_PACKAGES" /> ``` #### 3. **使用正确的API** - 如果是在应用内安装APK,应使用系统提供的`Intent`安装方式,而不是直接调用BMS接口: ```java Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(new File("/path/to/app.apk")), "application/vnd.android.package-archive"); startActivity(intent); ``` #### 4. **系统级解决方案(适用于系统开发者)** - **修改BMS源码**:如果确实需要在非shell环境下调用,可以修改BMS的权限检查逻辑(不推荐,会降低安全性)。在AOSP源码中,找到报错位置(通常为`BMS`服务的某个方法),移除对调用者的检查或放宽权限。 ```java // 示例:在PackageManagerService.java中 if (callerUid != Process.SHELL_UID) { // 抛出"caller not shell"异常 throw new SecurityException("caller not shell"); } ``` 修改为: ```java if (callerUid != Process.SHELL_UID && callerUid != Process.ROOT_UID) { // 允许root用户 throw new SecurityException("caller not shell or root"); } ``` ### 调试与验证: - **检查调用者UID**:在触发错误的位置打印当前调用者的UID,确认其是否为2000(shell用户的UID)。 ```java int uid = Binder.getCallingUid(); Slog.e("BMS", "Current UID: " + uid); ``` - **使用`ps`命令**:通过`adb shell ps -u shell`查看当前运行的shell进程,确认操作是否在shell环境中执行。 ### 日志分析(参考原始日志): 在提供的日志中,我们并没有直接看到`C01120/foundation/BMS: caller not shell`的错误条目,但根据错误码`C01120`可以推断是BMS模块的权限检查失败。注意日志中以下关键行: ``` 11-19 08:10:14.282 1590 58558 I C01311/foundation/AppMS: [ams_mgr_scheduler88]SubmitLoadTask: com.huawei.hmos.screenrecorder-com.huawei.hmos.screenrecorder.ServiceExtAbility ``` 这表明系统正在尝试加载一个扩展能力(ServiceExtAbility),可能涉及包管理操作。如果这个操作是由非shell进程(如普通应用)触发的,就可能引发该错误。 ### 总结: 该错误的根本原因是**权限不足**,解决方案的核心是**确保操作在shell环境执行**或**提升调用者权限**。对于普通应用开发者,应使用系统提供的安装API;对于系统开发者,可考虑修改BMS的权限检查逻辑(需谨慎)。 §§相关问题§§ 1. 如何获取Android系统的shell权限? 2. 普通应用如何安全地安装APK文件? 3. 如何修改AOSP源码以放宽BMS的权限检查? </think> ### C01120/foundation/BMS: "caller not shell"错误分析与解决方案 #### 1. **错误本质分析** 该错误发生在BMS(Bundle Manager Service)包管理系统,核心问题是**权限验证失败**: $$ \text{错误代码:C01120} \implies \text{权限校验}\{ \text{caller\_uid} \neq \text{shell\_uid}(2000) \} $$ 在Android系统架构中: ```mermaid graph LR A[应用进程] -->|请求安装/卸载| B(BMS服务) B --> C{校验调用者UID} C -->|匹配shell_uid| D[执行操作] C -->|不匹配| E[抛出'caller not shell'] ``` #### 2. **根本原因诊断** | 原因类型 | 具体场景 | 日志特征 | |-------------------|--------------------------------------------------------------------------|------------------------------------| | **权限缺失** | 普通应用直接调用系统级API | `Binder.getCallingUid()=10123` | | **签名不匹配** | 应用未使用平台签名 | `verifySignatures: mismatch` | | **SELinux限制** | 安全策略阻止非shell进程访问 | `avc: denied` | | **服务绑定错误** | 错误绑定到系统服务而非BMS服务 | `ServiceConnection: bind failed` | #### 3. **解决方案** ##### 3.1 权限修复方案 ```java // 正确声明系统权限 <manifest xmlns:android="http://schemas.android.com/apk/res/android" android:sharedUserId="android.uid.system"> // 必须项 <uses-permission android:name="android.permission.INSTALL_PACKAGES" /> </manifest> ``` **关键步骤**: 1. 使用**平台签名**编译APK ```bash java -jar signapk.jar platform.x509.pem platform.pk8 app.apk app-signed.apk ``` 2. 在`Android.mk`中声明系统应用属性 ```makefile LOCAL_CERTIFICATE := platform LOCAL_PRIVILEGED_MODULE := true ``` ##### 3.2 SELinux策略调整 在`device.te`中添加: ```sepolicy # 允许指定域访问BMS allow my_app_domain bms_service:service_manager find; ``` 通过`audit2allow`转换拒绝日志: ```bash adb logcat -d | grep avc: | audit2allow -M mypolicy ``` ##### 3.3 服务调用规范 禁止直接调用隐藏API,改用系统接口: ```java // 正确调用方式 Intent installIntent = new Intent(Intent.ACTION_INSTALL_PACKAGE); installIntent.setData(Uri.fromFile(apkFile)); startActivity(installIntent); ``` #### 4. **验证与调试** **权限验证命令**: ```bash adb shell dumpsys package com.your.app | grep userId # 正确输出:userId=1000(system) 或 2000(shell) ``` **SELinux状态检查**: ```bash adb shell getenforce # 应返回 Permissive 或 Disabled adb shell ps -Z | grep your_app # 检查安全上下文 ``` **动态调试**: ```bash adb logcat -s C01120:BMS:* *:S # 过滤BMS错误 ``` #### 5. **案例参考** 某系统应用安装失败日志: ``` E C01120/BMS: caller uid=10125 not shell (2000) W PackageInstaller: Install failed: [INSTALL_FAILED_INVALID_URI] ``` **修复后**: ``` I BMS: verifyCaller: shell access granted for uid=2000 I PackageInstaller: APK installed in 3.2s ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值