ZKX's LAB

服务和进程是相互依存的吗?是不是每个进程都会绑定一个服务? 进程内服务需要绑定吗

2021-04-09知识2

Android Service 为什么要绑定服务 仅仅是因为要获取服务中的方法吗 Android中Service是运行在后台的东西,级别与activity一样。既然说service是运行在后台的服务,那么它就是不可见的,没有界面的东西。你可以启动一个服务Service来播放音乐,或者记录你地理信息位置的改变,或者启动一个服务来运行并一直监听某种动作。Service和其他组件一样,都是运行在主线程中,因此不能用它来做耗时的请求或者动作。你可以在服务中开一一个线程,在线程中做耗时动作。服务一般分为两种:1:本地服务,Local Service 用于应用程序内部。在Service可以调用Context.startService()启动,调用Context.stopService()结束。在内部可以调用Service.stopSelf()或 Service.stopSelfResult()来自己停止。无论调用了多少次startService(),都只需调用一次stopService()来停止。2:远程服务,Remote Service 用于android系统内部的应用程序之间。可以定义接口并把接口暴露出来,以便其他应用进行操作。客户端建立到服务对象的连接,并通过那个连接来调用服务。调用Context.bindService()方法建立连接,并启动,以调用 Context.unbindService()关闭连接。多个客户端可以绑定至同一个服务。如果服务此时还没有加载,bindService()会先加载它。提供给可被其他。

服务和进程是相互依存的吗?是不是每个进程都会绑定一个服务? 不是。服务本身属于系统内的,进程则可以是某个软件。不管我们访问什么还是打开任何一个软件都会生成一个进程。跟服务无关。

Linux如何将进程绑定运行在指定CPU上 绑定cpu方式:c语言:sched_setaffinity(0,sizeof(mask),&mask)shell命令:在grup启动时传给内核参数:isolcpus=2-15,这里表示隔离第3到16个CPU,Linux程序只跑在第一和第二个CPU上,空闲的CPU我们可以指定跑进程了.这是内核文档里对内核参数的解释:isolcpus=[KNL,SMP]Isolate CPUs from the general scheduler.Format:.,or(must be a positive range in ascending order)or a mixture.,<;cpu number>;-This option can be used to specify one or CPUsto isolate from the general SMP balancing and schedulingalgorithms.You can move a process onto or off anisolated\"CPU via the CPU affinity syscalls or cpuset.begins at 0 and the maximum value isnumber of CPUs in system-1\".This option is the preferred way to isolate CPUs.Thealternative-manually setting the CPU mask of alltasks in the system-can cause problems andsuboptimal load balancer performance.linux nice 命令详解功能说明:设置优先权。语 法:nice[-n<;优先等级>;][-help][-version][执行指令]补充说明:nice指令可以改变。

#进程内服务需要绑定吗

随机阅读

qrcode
访问手机版