On Wed, 6 Sept 2023 at 12:09, Roberto A. Foglietta
<[email protected]> wrote:

> However, execution time does not change so much

Instead when multiple processes names are passed as arguments, the
execution time gap increases even more because pidof execution time
depends on the number of arguments while the function listed here
below does not. Therefore, I think that there is an algorithm change
to plan for the pidof applet that will move it from O(N) to O(1).

comm_pid()
{
    grep -nE "$(echo $* | tr ' ' '|')" /proc/[1-9]*/comm | cut -d/ -f3 | grep .
}

redfishos:~ # a=$(date +%s%N); pidof sshd dropbear telnetd httpd
yamui; b=$(date +%s%N); echo $((b-a))
678 673 675 725
456542916
redfishos:~ #  a=$(date +%s%N); comm_pid sshd dropbear telnetd httpd
yamui; b=$(date +%s%N); echo $((b-a))
673
675
678
680
725
95683125
redfishos:~ # echo $(( 456542916 / 956831 ))
477

redfishos:~ #  a=$(date +%s%N); comm_pid sshd dropbear telnetd httpd
yamui ash; b=$(date +%s%N); echo $((b-a))
1866
438
673
675
678
680
725
95632552
redfishos:~ # a=$(date +%s%N); pidof sshd dropbear telnetd httpd yamui
ash; b=$(date +%s%N); echo $((b-a))
678 673 675 725 1866
548829427
redfishos:~ # echo $(( 548829427 / 956326 ))
573

I hope this helps, R-
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to