Help with Commands - C

0

The idea is, from the entry of a pid by the user, stop it, but it is not working, do you have any ideas?

#include <stdio.h>
int main()
{

char proceso;
char command;
for(;;){
    command="kill ";
    printf( "Aca listo los procesos" );
    fflush(stdout); 
    system("ps -eo user,pid,%mem,%cpu --width 9 --sort -rss | head");
    fflush(stdout); 
    printf("Deme un pid para detener" );
    fflush(stdout);
    scanf("%s",&proceso);
    printf( "deteniendo el proceso PID: %s\n", proceso );
    fflush(stdout);
    command=command+proceso;
    printf( "El comando es: %s\n", command );
    fflush(stdout);
    int system(const char * command);

     } 


    return 0;

     } 
    
asked by Kevin Lincon 06.12.2016 в 18:28
source

1 answer

1

I think you need to send the signal to the process:

Remember that the kill command ends the processes by sending them a signal:

Example: kill -9 $PID In this case 9 is the number of the signal.

While killall , allows you to do it with the name of the process.

kill - > Here killall - > Here

It should be clarified that to "kill" the process you must have the privilege over the process.

    
answered by 06.12.2016 в 19:18