Find process by name and insert commands


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Find process by name and insert commands
# 1  
Old 08-03-2011
Find process by name and insert commands

I am writing a tcsh script that will open an already-running processs on a system, and give it a command. I want to have something similar to this:
Code:
http://www.cyberciti.biz/faq/kill-process-in-linux-or-terminate-a-process-in-unix-or-linux-systems/

But I need to be able to find the process and insert the command, either kill or something else, all in one line.

I'm thinking it would look something like this:
Code:
ps -ax | grep <process> | <now what?>

Please reply soon, as I need to get this to work quickly, though I am not at all sure what to do.

Last edited by Adorai; 08-03-2011 at 09:02 AM.. Reason: Correct bad format
# 2  
Old 08-03-2011
When you say give it a command, I believe you mean send it a signal, you can send signals via kill with the appropriate number as a flag eg.
Code:
kill -$SIGNAL_NUMBER $(ps ax | grep firefox-bin|grep -v grep |awk '{print $1}')

Or using the example you provide
Code:
kill -$SIGNAL_NUMBER $(pidof firefox-bin)

That said, despite your haste, you should have a read of TLDP IPC guide

Last edited by Skrynesaver; 08-03-2011 at 09:33 AM.. Reason: additional reading recommendation.
# 3  
Old 08-03-2011
Having seen the guide, I don't think sending a signal is what I need.
Here is the basic situation:
User A launches a process.
User B is logged in to the same system and needs to access the process to give it a command (what the script is for). Acceptable commands are start, stop, pause, and kill, kill ending the process entirely, while the other commands give it specific instructions.
Although from the format of your answer, it sounds like this should work:
Code:
start $(pidof <process>)

Or can that only be done with kill?
# 4  
Old 08-03-2011
How would User A give these commands to the process?
# 5  
Old 08-03-2011
User A starts seeing this:
prompt>
User A starts the process:
prompt> <process>
User A gives any of the aforementioned commands to the process:
prompt/process> <command>
# 6  
Old 08-05-2011
It sounds as though your process is going to have to have a signal handler so that the user B can send various signals (note that a signal handler can do whatever it likes when it receives any signal except SIGKILL(9) or you could implement a "management" shell that user B can log into and issue commands to the process on.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using sed to find and append or insert on SAME line

Hi, $ cat f1 My name is Bruce and my surname is I want to use SED to find “Bruce” and then append “ Lee” to the end of the line in which “Bruce” is found Then a more tricky one…. I want to INSERT ….a string… in to a line in which I find sometihng. So example $ cat f2 My name is... (9 Replies)
Discussion started by: Imre
9 Replies

2. UNIX for Dummies Questions & Answers

To run 5 commands at the same time with process from a list

I have many command is list in the variable lists,each command will run a very long time, so I want to run 5 commands at the same time with process till it complete run all the command, lists="aa bb cc dd xx gg blabla zz ......." ( a very long list) can some one point me the codes? ... (7 Replies)
Discussion started by: yanglei_fage
7 Replies

3. Programming

Find parent process (not process ID)

Hi: I have a program written in FORTRAN running on AIX platform. It is because missing of documentation and without root password, therefore we want to modify the program so that we can find out which script/program that call this FORTRAN program. I have google for few days, all of them are... (3 Replies)
Discussion started by: cstsang
3 Replies

4. Shell Programming and Scripting

Multiples commands between pipes and a single process

Hi I have this script: #!/bin/ksh cmd1 | cmd 2 |cmd 3| cmd4 which it creates 4 process.... Is possible to create a single process PID1 which include all commands? Thanks Israel (2 Replies)
Discussion started by: iga3725
2 Replies

5. Shell Programming and Scripting

Sed find and insert

Hi All I'm trying to insert a pattern if a pattern is found in a file. This is my sample file "PDA"|"Celvin"|"PRJ_NA"|"Completion_Units"|25 "PDA"|"Celvin"|"PRJ_AB"|"Completion_Units"|250 I would like to output as "PDA"|"Celvin"|"PRJ_NA"|"Completion_Units"|"Done"|25... (3 Replies)
Discussion started by: Celvin VK
3 Replies

6. UNIX for Dummies Questions & Answers

Executing a sequence of commands as a single background process

I'm writing a PHP script which will take a given media file and convert it into a flash (flv) file. In addition to this, once the flv file has been generated I create two thumbnails (of different sizes) from the newly generated flv file. In order to do this I'm calling ffmpeg from the command... (4 Replies)
Discussion started by: phatphug
4 Replies

7. UNIX for Advanced & Expert Users

commands not working if the executed from forked process

Hi, I have an application where if it runs indivisually could able to execute commands (like system("ls")) and could able to execute tcl script. Same application if started from health monitor process (From health monitor process my application will be forked), it could not execute the... (1 Reply)
Discussion started by: chandrutiptur
1 Replies

8. UNIX for Advanced & Expert Users

can some one give me some link about process and job control commands

can some one give me some link about process and job control commands (2 Replies)
Discussion started by: alokjyotibal
2 Replies

9. Shell Programming and Scripting

Omitting some filenames for commands to process

hello all, this topic might have been discussed but I couldn't find it with searching. I am trying to do a for command that will dos2unix files one by one and save it under directory called backup (backup is in the same directory with other files). When I do: for i in * do dos2unix $i... (5 Replies)
Discussion started by: milhan
5 Replies

10. Shell Programming and Scripting

how to find the chid process id from given parent process id

how to find the chid process id from given parent process id.... (the chid process doesnot have sub processes inturn) (3 Replies)
Discussion started by: guhas
3 Replies
Login or Register to Ask a Question