2017-01-06 17:12:57 +01:00
|
|
|
|
2021-06-12 23:34:41 +02:00
|
|
|
/* waits for LASTPID or pid in param */
|
|
|
|
int cmd_waitfor(char param[]) {
|
|
|
|
int i, n, sel, sel_pid;
|
|
|
|
char *buf1k;
|
|
|
|
unsigned PID;
|
|
|
|
short STATE;
|
|
|
|
|
|
|
|
sel = param && strlen(param) > 0;
|
|
|
|
sel_pid = LAST_PID;
|
|
|
|
if (sel) {
|
|
|
|
sel_pid = atoi(param);
|
2017-01-06 17:12:57 +01:00
|
|
|
}
|
2021-06-12 23:34:41 +02:00
|
|
|
if (0 == sel_pid) return FALSE;
|
|
|
|
|
|
|
|
printf(CMD_WAITFOR_FMT, sel_pid);
|
|
|
|
|
|
|
|
buf1k = malloc(1024);
|
|
|
|
if (NULL == buf1k)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
for (i = 1;;i++) {
|
|
|
|
n = kol_process_info(i, buf1k);
|
|
|
|
PID = *(buf1k+30);
|
|
|
|
STATE = *(buf1k+50);
|
|
|
|
if (PID == sel_pid)
|
|
|
|
if(9 == STATE)
|
|
|
|
goto exit_normal;
|
|
|
|
else break;
|
|
|
|
if (i == n)
|
2017-01-06 17:12:57 +01:00
|
|
|
goto exit_normal;
|
|
|
|
}
|
2021-06-12 23:34:41 +02:00
|
|
|
kol_sleep(10); // 100ms
|
2017-01-06 17:12:57 +01:00
|
|
|
}
|
|
|
|
|
2021-06-12 23:34:41 +02:00
|
|
|
exit_normal:
|
|
|
|
free(buf1k);
|
|
|
|
return TRUE;
|
2017-01-06 17:12:57 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|