GetTask new version

Cesare Pizzi (cpizzi@globalnet.it)
Sun, 15 Feb 1998 19:54:01 +0100


This is a multi-part message in MIME format.
--------------0850236A3FB33CE32A7958AB
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hello All,

here attached you'll find the new version of the "gettask" calls.
As suggested by Randolph, I modified the getnexttaskid call:

gettask(TaskName) This call returns the number of running
"TaskName" processes on the
system

getfirsttaskid(TaskName) This call returns the first PID of
"TaskName"

getnexttaskid(TaskID) This call returns the next PID of process
pointed out by TaskID. In
this way there are
not problems if some
processes call the function
at the same time.

Let me know your comments.

Thanks and regards,

Cesare

--------------0850236A3FB33CE32A7958AB
Content-Type: text/plain; charset=us-ascii; name="task.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="task.c"

/*
*
* Version 0.5.5 of a couple of stupid system calls to get some information
* about the tasks running on the system.
* Author: Cesare Pizzi (cpizzi@bigfoot.com)
* Thanks to Randolph Bentson
*
*/

#include <linux/sched.h>

/*
* Retruns the number of "cmd" processes running on the system
*/
asmlinkage int sys_gettask(const char *cmd)
{
int i;
int count = 0;
int error;

/* Temporary pointer for the parameter */
char *tmp;

if ((error = getname(cmd,&tmp)) != 0) {
return(error);
}

for(i=0; *(task + i) != NULL; i++) {

/* Check if the task is the same wanted by the caller */
if ((strcmp(tmp,task[i]->comm)) == 0) {
count++;
}
}

putname(tmp);

return(count);
}

/*
* Retruns the PID of the first process pointed out by the parameter.
*/

asmlinkage pid_t sys_getfirsttaskid(const char *cmd)
{
char *tmp;
int error;
int i;

if ((error = getname(cmd,&tmp)) != 0) {
return(error);
}

for(i=0; *(task + i) != NULL; i++) {

/* Check if the task is the same wanted by the caller */
if ((strcmp(tmp,task[i]->comm)) == 0) {

/* PID catched */
return(task[i]->pid);
}
}

putname(tmp);

return(0);
}

/*
* Retruns the PID of the next process pointed out by the parameter.
* Now the parameter is the PID of the process
*/
asmlinkage pid_t sys_getnexttaskid(const pid_t id)
{
int i,x;

/*
* Look for the PID name linked to the parameter
*/
for (i=0; *(task + i) != NULL; i++) {

if (task[i]->pid == id) {
/* PID found */
break;
}
}

if (*(task + i) == NULL) {
/* PID not found */
return(0);
}

/* Look for the next PID of the command found */
x=i;
x++;
while (*(task + x) != NULL) {

if ((strcmp(task[x]->comm,task[i]->comm)) == 0) {

/* Found */
return(task[x]->pid);
}

x++;
}

return(0);
}

--------------0850236A3FB33CE32A7958AB--

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu