Communication between processes in Unix


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Communication between processes in Unix
# 1  
Old 12-23-2009
Bug Communication between processes in Unix

hi folks!!
I was stuck with a little problem where i needed to communcate between two processes, i.e., send a command to the parent process from the child process as soon as the child process terminates.This was required when i wanted to create a log using the script command in a bourne shell.The following is the script that i am running:
Code:
#!/bin/sh
set -x
echo `date`|sed "s/[:' ']//g" >name
 head -1  name | read name1
script ./logs/$name1.txt
if [ $0=exit ];
then
exit
logout #*#
fi

~
#*# At this point in the code, when the user wants to exit, i need to ask the parent process to logout (send the logout command in the process) so that the user finally gets out of the server.


Can anyone help me in this?

Last edited by pludi; 12-23-2009 at 07:52 AM.. Reason: code tags, please...
# 2  
Old 12-23-2009
Quote:
Originally Posted by bdiwakarteja
hi folks!!
I was stuck with a little problem where i needed to communcate between two processes, i.e., send a command to the parent process from the child process as soon as the child process terminates.

A child process cannot affect its parent.

The parent must use the output or exit status of the child.
Quote:
This was required when i wanted to create a log using the script command in a bourne shell.The following is the script that i am running:
Code:
#!/bin/sh
set -x
echo `date`|sed "s/[:' ']//g" >name


Why echo?

Why sed?

Why not use a format string with date?
Quote:
Code:
 head -1  name | read name1


Why use head? (And the name1 variable will not be available anywhere else in the script unless you are using ksh)

Code:
read name1 < name

But why are you using a temporary file?
Quote:
Code:
script ./logs/$name1.txt
if [ $0=exit ];


That will always be true (or a syntax error if $0 contains spaces).

Why would you expect $0 to contain exit? $0 contains the path to the current script.
Quote:
Code:
then
exit
logout #*#
fi

~
#*# At this point in the code, when the user wants to exit, i need to ask the parent process to logout (send the logout command in the process) so that the user finally gets out of the server.


Can anyone help me in this?
# 3  
Old 12-23-2009
Bug communication

hi.. I am sorry for confusing you on this.Trust me, i am just a beginner in shell scripting. I was merely trying to create a file containing all the commands and the outputs that the user tries on the shell and save it with the filename of the output of the date command modified with the sed command. Thats why i used sed command to create the filename and $name1 will contain the output of the date command after filtered.
But finally made a mistake in the $0 line of the command as u rightly pointed out.

But, is there a way that we can send a number as an exit status to the parent process and the latter then determines the next action to be carried out.If yes, whats the command?

Thanks in advance.

Last edited by bdiwakarteja; 12-23-2009 at 02:36 PM.. Reason: corrections
# 4  
Old 12-23-2009
Quote:
Originally Posted by bdiwakarteja
hi.. I am sorry for confusing you on this.Trust me, i am just a beginner in shell scripting. I was merely trying to create a file containing all the commands and the outputs that the user tries on the shell and save it with the filename of the output of the date command modified with the sed command. Thats why i used sed command to create the filename and $name1 will contain the output of the date command after filtered.

There is no need to use sed. You can use a format string as an argument to date:

Code:
filename=$(date +%Y-%m-%d.txt)

Quote:
But finally made a mistake in the $0 line of the command as u rightly pointed out.

But, is there a way that we can send a number as an exit status to the parent process and the latter then determines the next action to be carried out.If yes, whats the command?

Normally, the exit status of a command is contained in the special parameter, $?, but script always seems to exit without an error.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

SPAWN Multiple Processes in Unix

Hi, I have three files in my IN directory.Each file should be copied 25 times using for loop.Each file processing should run in parallel?How to spawn multiple processes in unix?Any help would be appreciated. Thanks, Liyakath (7 Replies)
Discussion started by: liyakathali
7 Replies

2. UNIX for Dummies Questions & Answers

Processes in Unix

I am trying to play and create processes and found this piece of code.... int myMain(int argc , char* argv){ childID = 0; for (j=1;j<3;j++) if (childID = fork()) break; fprintf(stderr, " process ID:%d parent ID:%d child ID:%d\n", getpid(), getppid(), childID); return... (3 Replies)
Discussion started by: joker40
3 Replies

3. Shell Programming and Scripting

Finding the age of a unix process, killing old processes, killing zombie processes

I had issues with processes locking up. This script checks for processes and kills them if they are older than a certain time. Its uses some functions you'll need to define or remove, like slog() which I use for logging, and is_running() which checks if this script is already running so you can... (0 Replies)
Discussion started by: sukerman
0 Replies

4. Shell Programming and Scripting

Unix to Windows Communication

Hi All, I need to come up with a shell script that logs into a windows system and fires a batch/executable file in it. Any idea how to go about doing this? Please help. Regards, Agniv. (4 Replies)
Discussion started by: agnivaccent
4 Replies

5. UNIX for Advanced & Expert Users

Processes Communication Only with flags!

hello everybody and a happy new year! i am trying the client-server model...i have no problem with sockets etc... especially for server:there is a father who is listening for TCP connections from clients,the later send commands which parent shares to his children. then children execute... (1 Reply)
Discussion started by: vaggelakis
1 Replies

6. UNIX for Dummies Questions & Answers

UNIX processes

hey, I know that there are bash commands like top or ps that allow me to monitor processes. But how can i monitor 1 process and log the output in a file? thx in advance Stephane Rufer (3 Replies)
Discussion started by: rufman
3 Replies

7. Shell Programming and Scripting

Unix Kill processes

Hi guys, I am new to Unix shell scripting. Can anyone of you tell me how to kill all the processes at a time for a particular user?(No listing the process ID of each process in the kill -9 command). Thanks in Advance, -Hary (5 Replies)
Discussion started by: tadi18
5 Replies

8. UNIX for Dummies Questions & Answers

Windows Unix communication

Hi All I am using a QTP testing tool which is in windows and I need to connect to a unix machine from the windows and execute a shell script which will throw some log files and i need to open one log file and get a number (no. of records) and use it in my Testing tool script which is in... (3 Replies)
Discussion started by: arulraj2007
3 Replies

9. UNIX for Advanced & Expert Users

Serial Communication in UNIX

Hi, I am working on serial communication on Unix. Can anyone guide me through it. The steps required for RS 232 communication and can i do serial communication even if i dont have super user previledges. Thankx, Vicky (1 Reply)
Discussion started by: Vicky
1 Replies

10. UNIX for Dummies Questions & Answers

communication unix/windows

Hi everybody, I have a speech recognition application which works on windows and which create a text file. My main application works on unix and I need to get (or simply read) in real time the text file. I can't use a soft like Samba because it is not authorized in my company. I would like a... (1 Reply)
Discussion started by: kintoo
1 Replies
Login or Register to Ask a Question