LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-23-2004, 01:29 AM   #1
melinda_sayang
Member
 
Registered: Dec 2003
Location: Petaling Jaya
Distribution: Ubuntu
Posts: 475

Rep: Reputation: 31
kill and detect spesific application


I am writing program and when the user launch my program, my program will detect whether the user has launch abiword. If he does, my program will kill it before doing some job for the user.

How can I do that? In C++ please.......
How can I detect the "abiword" program present?
How can I kill it? I only know the word not the pid.......

Thank you...............
 
Old 05-23-2004, 01:34 AM   #2
villie
Member
 
Registered: Apr 2004
Location: Pakistan
Distribution: RedHat
Posts: 46

Rep: Reputation: 15
You can use fork a new process "killall" and give it the argument "abiword".
 
Old 05-23-2004, 02:25 AM   #3
melinda_sayang
Member
 
Registered: Dec 2003
Location: Petaling Jaya
Distribution: Ubuntu
Posts: 475

Original Poster
Rep: Reputation: 31
Thanx, but is there any elegant way to do that by code not forking?
 
Old 05-23-2004, 02:40 AM   #4
eshwar_ind
Member
 
Registered: Feb 2004
Location: Bangalore
Distribution: Redhat
Posts: 144

Rep: Reputation: 15
With out forking To solve that problem, I think you have to look into /proc directory and get the pids of processes with the name abiword. When ever you get a match just send a kill signal to it. This method is an indirect way( bulky one ) . But it avoids the creation of another process.
This is not elegant way .
Tell me Why dont you want to use fork();
 
Old 05-23-2004, 03:02 AM   #5
melinda_sayang
Member
 
Registered: Dec 2003
Location: Petaling Jaya
Distribution: Ubuntu
Posts: 475

Original Poster
Rep: Reputation: 31
Ok, I am happy enough now to kill spesific application which I know the name but not the pid by forking() but how can I detect the presence of spesific application? So when the user run my program, it will pop up like this:
"upps, you are running abiword. I don't like it. I will kill it!!!! "
and it will kill abiword by forking() but first I need to know how can I detect abiword?
You said by looking into proc directory. I have no clue how to do that way?
 
Old 05-23-2004, 03:38 AM   #6
eshwar_ind
Member
 
Registered: Feb 2004
Location: Bangalore
Distribution: Redhat
Posts: 144

Rep: Reputation: 15
see /proc/ * / stat file or /proc/ */cmdline
Contains the executable file names.
There * is the pid of the currently executing process.
If you have any doubts feel free to ask me.
Just explore the /proc directory.

This is the way of reading a directory entry name from proc directory;

void Read_Proc( char copt )
{

DIR *dfd; /* A pointer to hold the pointer ret by opendir */
struct dirent *rdir_ent; /* A pointer to read the dirent structure */
struct pr_det prdet; /* Holds the details about a process */
dfd = opendir( "/proc" ); /* Open the /proc dir */


/* Read the dir entries until the end of dir is read */
while( ( rdir_ent = readdir( dfd ) ) != NULL )
{

/* Check for the digit in first character of the file name */
if( isdigit( *rdir_ent->d_name ) )
{


prdet = parse_dir( rdir_ent->d_name ); /* Here you have to go in that */
/* directory open the stat or */
/* cmdline, find the exe file name*/
/* IF it matches with abiword just
/* send kill to the directory name */
/* before sending kill convert that dir
name to integer */

}

}
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
kill -9 for ncurses application problem arunka Programming 2 11-27-2005 12:09 PM
kill procesed application fireedo SUSE / openSUSE 4 05-10-2005 11:24 AM
x server kill application keyboard shortcut/hotkey hypermegachi Linux - Newbie 2 07-25-2004 02:37 PM
Kill -9 not killing application, connected with cdrom busy error? vdemuth Linux - Software 5 04-11-2004 02:33 PM
How to detect non ascii filenames from an application which doesn't support UNICODE ( pankajtakawale Solaris / OpenSolaris 0 02-05-2004 06:28 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:44 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration