In bash I would write something like this :
Code:
full_progname=`readlink -e "$0"`
base_progname="${full_progname##*/}"
ALL_PIDS=`pidof "$base_progname"`
pid_program=$$
PIDS_TO_KILL=`echo "$ALL_PIDS" | tr ' ' '\n' | grep -v -w "$pid_program"`
for a_pid in $PIDS_TO_KILL
do
kill -9 $a_pid
done
I have a line in C as
Code:
system("kill `pidof freememapplet | grep ' ' | cut -f 2 -d ' '`");
or
Code:
system("FREEMEMPIDS=`pidof -o $$ -o %PPID freememapplet`;for PiD in $FREEMEMPIDS;do kill $PiD;done");
which works as long as the new instance has a higher pid number as the former instance . $$ and %PPID also refer apparently to the system() call, not to the program .
/* The program "freememapplet" is a Puppy Linux specific tray application . */
These variables I am able to compute already :
Code:
char* PROGRAMNAME = argv[0];
pid_t pid;
int MYPID = getpid();
extern char *__progname;
printf("%s" " " "%s" "\n", PROGRAMNAME, __progname);
printf("%d" " " "%d" "\n", pid, MYPID );