Re: [PATCH v2] taskset: Accept 0 pid for current process

Karel Zak <[email protected]>
Newsgroups org.kernel.vger.util-linux
Message-ID <lscxfxbzi6j667md5buwprb5muuzpmsdpvvpmbdk7jvsq2rtxo@ucpthvyj2efw>
On Tue, Jul 01, 2025 at 08:35:11AM +0200, Jesse Rosenstock wrote:
> A reasonable alternative would be to interpret just `taskset` (currently
> an error) as printing the current mask.  This seems less orthogonal,
> and a better use may be found for plain `taskset` in the future.

Unfortunately, all schedutils have an odd command-line semantic.

>                 case 'p':
> -                       pid = strtopid_or_err(argv[argc - 1],
> _("invalid PID argument"));
> +                       /*
> +                        * Like strtopid_or_err() but accept 0 for this process,
> +                        * like sched_getaffinity()/sched_setaffinity() do.
> +                        */
> +                       pid = (pid_t) str2num_or_err(
> +                               argv[argc - 1], 10, _("invalid PID argument"),
> +                               0, SINT_MAX(pid_t));

chrt uses:

                     /* strtopid_or_err() is not suitable here; 0 can be passed.*/
                        ctl->pid = strtos32_or_err(argv[argc - 1], _("invalid PID argument"));

 would be this enough?

> +                       if (pid == 0)
> +                               pid = getpid();

Yes, this is probably better than make many other changes to the code.

    Karel

-- 
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.