|Code| Processes communicate by IPC methods

Threads can shares the same resources such as address space, file descriptors, stack and other process related attributes in the same process.
BUT Processes can not share resources directly.

Processes will communicate to each other by IPC method.
There are two ways:
 1. Shared Memory
 2. Message passing: Socket, FIFO, POSIX message, dbus

The following methods, which we often see, belong to message passing.
Pipe
Socket
Remote Procedural calls (RPCs)


Originally, I though it is a basic interview question and everyone has at least a common answer .
Until I found someone did not know , I know I was wrong.



https://www.geeksforgeeks.org/inter-process-communication-ipc/
https://stackoverflow.com/questions/200469/what-is-the-difference-between-a-process-and-a-thread

|Design| bit map

如果你的某個宣告有多重意義,
但你一次只想知道某的欄位的狀態,可以善加利用 bit map

舉例:

#define status1 (uint_8) 1<<0
#define status2 (uint_8) 1<<1
#define status3 (uint_8) 1<<2

uint_8 test_case = 2;
int test_hex_case = 0xFA;

If( test_case & status1 ){ // false; 00000000 <- 00000010 & 00000001
  //do nothing
}
If( test_case & status2 ){ // true, not zero; 00000010 <- 00000010 & 00000010
  //do something
}
If( test_hex_case & status2 ){ // true, not zero;
// 0xFA = 1111 1010
// 00000010 <- 1111 1010 & 00000010
  // do something
}

|Job| Application No Response Analysis

ANR 的發生情形,通常是時間到了還沒有回應!所以掌握這個想法,就比較好找 Code。

比較常見有三種情形:

  1. Service Timeout
  2. BroadcastQueue Timeout
  3. ContentProvider Timeout

 

Case 1. Service Timeout

 a. Service 啟動後,會發送 SERVICE_TIMEOUT_MSG 消息
 b. Service 刪除後,就會刪除 SERVICE_TIMEOUT_MSG 消息
 c. 如果 SERVICE_TIMEOUT_MSG 未删除,時間到後就會 ANR

 呼叫 ActiveServices 的 serviceTimeout 方法進行處理,
 serviceTimeout方法邏輯:

 if (anrMessage != null) {
  mAm.appNotResponding(proc, null, null, false, anrMessage);
 }

 

Case 2. BroadcastQueue Timeout

 BroadcastQueue 中的 mHandler 收到 BROADCAST_TIMEOUT_MSG 消息時會觸發

 // 正常要發送消息前
 broadcastTimeoutLocked(false);

 // 發送消息,鎖住
 case BROADCAST_TIMEOUT_MSG: {
  synchronized (mService) {
   broadcastTimeoutLocked(true);

 // ANR
 在 broadcastTimeoutLocked 方法中,首先取得 anrMessage 字串

 anrMessage = “Broadcast of ” + r.intent.toString();

 mHandler.post(new AppNotResponding(app, anrMessage));
 mService.appNotResponding(mApp, null, null, false, mAnnotation);

 

Case 3. ContentProvider Timeout

 MainHandler 的 handleMessage CONTENT_PROVIDER_PUBLISH_TIMEOUT_MSG

 private final void processContentProviderPublishTimedOutLocked(ProcessRecord app) {
cleanupAppInLaunchingProvidersLocked(app, true);
 removeProcessLocked(app, false, true, “timeout publishing content providers”);
 }

 app.kill(reason, true);

 

ref.

https://blog.csdn.net/u012439416/article/category/7261623