But the issue is the PID that I print before sending to through the method and the PID that I print after receiving it in the method are totally different.I can't figure this out.
void killbyPIDprocess(struct process** ptr,char* p)
printf("Inside while loop");
printf("Kill process of PID %d\n",p);
void loop(char *input)
struct process **ptr=(struct process*) malloc (BUFFERSIZE);//Is the array that contains pointers to all the processes created.
int ci=0;int i=0;
char* pid=(char*)malloc (BUFFERSIZE);
printf("%d\n",*p); will print a numeric code for the first char in a buffer, so you have to use
%s format specifier -
printf("%s\n", p); to get the same results.
if(strcmp(ptr[i]->pid,p)==0) is also incorrect.
process::pid member has an
pid_t type, which is an signed integer. Using it in the string comparison routines is an undefined behavior (not sure it will even compile). To compare PIDs you have to convert your string data to the integer, using for example an
atoi function. Then you could directly compare them with the