I actually posted this problem on a different forum, but figured this would be a more appropriate place to post it.
OK so I've created my own shell, but I can't get the background process function to run properly! What I want to do is to run a process in the background, and also print when the job is finished. The printing part is where I've been having some problems.
So if I type sleep 5 &, it works and prints out when finished. However, if I type sleep 5 &, and then type in another command like ls or ps after it, the shell hangs and it prints out that it's finished when it clearly has not finished.
OUTPUT:
I pressed enter a few times the first time I ran sleep 5 in the background, then after 5 seconds, it printed out the pid perfectly! But notice what happens when I ran sleep 5 in the background and then ran ls following it right afterwards. System printed out my files/folders but posted the pid and got hung.
Hello all,
How do I start a background process and save the process id to a file on my system. For example %wait 5 & will execute and print the process id. I can't figure out how to get it to a file. I've tried: > filename 0>filename 1>filename.
Any assistance is most appreciated.
Thanks,
Jim... (10 Replies)
Hello All,
I am a newbie in Shell script programming, and maybe you can help me with my query.
I need to write a shell script (mntServer.ksh) that will start a background process and also to be able to run another script.
The mntServer.ksh script contains:
#!/bin/ksh... (1 Reply)
I have a following program:
echofunc()
{
filename=$1
echo "reading $filename"
while read line
do
echo $line;
sleep 6;
done < $filename
}
split -5 new.dat
ls x* > input.dat
while read file
do
echofun $file &
done < input.dat (3 Replies)
hey all,
i am working on sun solaris machine and i want to start a process in background using shell script (actually i wanna start tomcat server using shell script). please dont tell me that append a & at last because this is not working in the shell script. i have also used nohup and... (8 Replies)
What I need to learn is how to use a script that launches background processes, and then kills those processes as needed.
The script successfully launches the script. But how do I check to see if the job exists before I kill it?
I know my problem is mostly failure to understand parameter... (4 Replies)
I am trying to create a service to always run and monitor a script that has a tendency to hang, we could not find what is causing it to hang so are in the process of completely reprogramming just about everything, however, that will take upto 6 months.
So I need to create this to monitor the... (5 Replies)
Hi,
I am using net::ftp for transferring files now i am trying in the same Linux server as a result ftp is very fast but if the server is other location (remote) then the file transferred will be time consuming.
So i want try putting FTP part as a background process. I am unaware how to do... (5 Replies)
Hi, i was looking for an answer for some trouble im having runing a script in the cron, thing is, that when i run it manually it works just fine. But when cron runs it, it just doenst work. I saw a reply on a similar subject, suggesting that the . .profile worked for you, but im kind of... (9 Replies)
Hi,
I am trying to create a shell script to automate the following process of getting svn stats:-
Step1:- cd to checkout location.
Note that the checked code have multiple modules in respective folders
Step2:- Execute this command inside each module:-
svn log -v --xml >... (0 Replies)
Hi,
I have written a menu driven shell script in which as per the choice, I run the another script on background.
For eg:
1. get info
2)process info
3)modify info
All the operations have different scripts which i schedule in background using &.
However I wish to display the error... (0 Replies)
Discussion started by: ashima jain
0 Replies
LEARN ABOUT OSF1
bind_to_cpu
bind_to_cpu(3) Library Functions Manual bind_to_cpu(3)NAME
bind_to_cpu - Bind execution to a specific CPU.
LIBRARY
Mach Library (libmach.a)
SYNOPSIS
#include <sys/types.h> #include <sys/resource.h>
int bind_to_cpu(
pid_t pid,
unsigned long cpu_mask ,
unsigned long flag );
PARAMETERS
Specifies the target pid. You must have access rights to the pid. Specifies the CPU on which the thread should run. The target CPU is the
bit index in the mask. If you set more than one bit, an error is generated. A cpu_mask of zero clears any previously set CPU binding.
Specifies options to CPU binding. Currently only the option BIND_NO_INHERIT is supported. When set, this option causes child processes
and threads to not inherit the CPU binding.
DESCRIPTION
Upon return from bind_to_cpu, all threads of the target pid are running on the target CPU. Bound threads are not eligible for execution on
any other CPU. You release CPU binding by invoking bind_to_cpu with a cpu_mask of zero.
EXAMPLES
/*
* Fork child process and force it to run on cpu number 3.
* Processes created by the forked child will not inherit bindings.
*/ #include <sys/resource.h> #include <sys/sysinfo.h> #include <sys/signal.h> #include <sys/types.h>
#define CPU_3 0x8 /* Bit 3 set */
main() {
pid_t pid;
if (pid = fork()) { /* parent */
if (bind_to_cpu(pid, CPU_3, BIND_NO_INHERIT)) {
kill(pid, SIGKILL);
exit(1); /* bind_to_cpu() will print error msg */
}
sleep(2); /* wait for child to print CPU */
}
else { /* child */
long cpu_num;
sleep(1); /* wait for parent to bind CPU */
getsysinfo(GSI_CURRENT_CPU, &cpu_num, 0L, 0L, 0L);
printf("child running on CPU %d
", cpu_num);
} }
In this example, the CPU_3 symbol is defined so that bit three in the bit mask is set. When the pid returned from the fork routine identi-
fies the parent routine, the bind_to_cpu routine is called. This routine binds the child process to CPU number three, as specified in the
CPU_3 symbol. When the pid returned from the fork routine identifies the child routine, the child routine sleeps to give the parent routine
time to set its CPU binding. Then it uses the getsysinfo call to determine its CPU and displays its CPU with the printf routine.
If the return value from the bind_to_cpu routine indicates an error, the parent process kills the child process and exits with an error
status.
RETURN VALUES
Upon successful completion, bind_to_cpu returns zero. Upon error, a -1 is returned.
RELATED INFORMATION
Commands: runon(1)
Functions: getsysinfo(2) delim off
bind_to_cpu(3)