[LTP] [PATCH 1/2] syscalls/getpid01: Convert to new API

Cyril Hrubis chrubis@suse.cz
Wed Feb 24 11:28:52 CET 2021


Hi!
> +static void verify_getpid(void)
>  {
> +	TEST(getpid());
>  
> -	tst_sig(NOFORK, DEF_HANDLER, cleanup);
> -
> -	TEST_PAUSE;
> +	if (TST_RET == -1)
> +		tst_res(TFAIL | TTERRNO, "getpid()");
> +	else
> +		tst_res(TPASS, "getpid() returns %ld", TST_RET);

The POSIX actually mandates that getpid() cannot fail and is always
successful. Given that this test seems to be useless and could be
removed or replaced with something more sane.

I guess that what we can do is to check if the return value from
getpid() is greater than 1, since pid 1 is special no other process than
init can have pid == 1. And the value has to be smaller or equal to
/proc/sys/kernel/pid_max as well.

So what would I do here would be:

* read /proc/sys/kernel/pid_max value
* loop 100 times or so
  - fork a child
  - check that the pid in child is > 1 and <= pid_max

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list